Reputation: 4099
I am trying to open an external link in a modal. The following code works fine:
$('[data-link]').on('click', function(event){
event.preventDefault();
var link = $(this).attr('href');
window.open(link, 'newwindow', 'width=300, height=250');
});
But if I put the window.open
function inside a delayed function call, I get a "Pop-up blocked" message on my browser:
$('[data-link]').on('click', function(event){
event.preventDefault();
var link = $(this).attr('href');
_.delay(function(){
window.open(link, 'newwindow', 'width=300, height=250');
}, 0);
});
It doesn't matter how much the delay is, it just doesn't work with a delayed call. Does anyone know why this happens and how I can make it work?
Upvotes: 0
Views: 931
Reputation: 887433
Popup blockers will only allow you to open a popup in direct response to user events.
Once you call setTimeout()
, you're no longer in direct response to an event and can't get through.
Upvotes: 2