Open Page in New Window Without Popup Blocking

Avoid browser popup blockers

The general rule is that popup blockers will engage if window.open or similar is invoked from javascript that is not invoked by direct user action. That is, you can call window.open in response to a button click without getting hit by the popup blocker, but if you put the same code in a timer event it will be blocked. Depth of call chain is also a factor - some older browsers only look at the immediate caller, newer browsers can backtrack a little to see if the caller's caller was a mouse click etc. Keep it as shallow as you can to avoid the popup blockers.

Allow window.open to open new window and not popup

The window opened by window.open will always be regarded as a pop-up to block by browsers when the function is triggered without a user action initiating it.

That means that for example that these will not be blocked:

$('a').on('click.open', function(e) { e.preventDefault(); window.open('http://disney.com') });

Chrome even allows other events to trigger the popup, while firefox will not allow this:

$(document).on('keydown', function(e) { window.open('http://stackexchange.com') });

And this will be blocked:

$(document).ready(function() { window.open('http://stackoverflow.com') });

So, unless you're triggering the window.open after a user action, you can never be sure that your window won't be blocked.

Window.Open without popup-blocker

You can't - because that's what popup blockers do: they block popup windows (i.e. calls to window.open or invocations of target="_blank" links) unless it is directly in response to a user mouse action.

Opening popups when a browser window is closed was a common tactic of "pop-under" ads in the early 2000s, and it irritated users, that's why Firefox and IE6's popup blocker block them, and there is no way around it for you unless you ask the user to disable their popup blocker on your site (and I think you'll find most of them will have no idea how to do that).

What are you trying to accomplish anyway? What is the content of this popup that you want the user to see? What other approaches have you tried?



Related Topics



Leave a reply



Submit