1

I want to default to target=_blank if window.open() fails.

Eg. The user clicks a link that invokes window.open(). However, the popup is blocked by a popup blocker. In this scenario, I want a new window to open instead. Is this possible?

P.S. I have jQuery loaded.

Leo Jiang
  • 24,497
  • 49
  • 154
  • 284
  • This may help: http://stackoverflow.com/questions/668286/detect-blocked-popup-in-chrome Or this: http://thecodeabode.blogspot.com/2010/11/window-open-popup-blocker-detect-for.html – gen_Eric Apr 18 '12 at 18:38

1 Answers1

0

Try this

Assuming that this is your A tag

<a href="http://www.w3schools.com" id="myLink" target="_blank">Click me</a>

Then using jquery, add a click event handler to this:

$("#myLink").click(function(e){
    if(!window.open("http://www.w3schools.com")){
        e.preventDefault();
    } 
});
walmik
  • 1,440
  • 2
  • 13
  • 30
  • 1
    This won't work on Chrome. Chrome returns a valid `Window` object from `window.open` even if the popup is blocked. – gen_Eric Apr 18 '12 at 19:57