Created
September 5, 2014 00:53
-
-
Save miguelmota/a3ad17e9e0fdc0a00cbd to your computer and use it in GitHub Desktop.
Open window in new tab, avoiding popup blocker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var link = document.getElementById('link'); | |
function open() { | |
var w = window.open('', 'MyWindow'); | |
// Ajax call | |
setTimeout(function() { | |
w.location.href = 'http://example.com'; | |
}, 100); | |
} | |
link.addEventListener('click', open); |
This doesn't work because the location.href
is set inside a callback function for setTimeout()
. Even though the timer is triggered by the user, it shouldn't work. The browser sees this as an automated timer triggering the redirection. The location.href
must be inside a user-driven event callback for a "popup" to be allowed.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi ,
Its not working. Still showing pop blocker option when trying to open in new window.