2

Possible Duplicate:
How can I detect if a browser is blocking a popup?

I want to open a new window (onclick) to a page on Facebook (facebook.com/sharer.php).

However, if this fails due to pop up blockage, I want to detect it and change it to a link instead (new tab).

How can I do that?

Community
  • 1
  • 1
TIMEX
  • 259,804
  • 351
  • 777
  • 1,080

2 Answers2

5
if(!window.open()){
//pop up failed.
}
Pheonix
  • 6,049
  • 6
  • 30
  • 48
  • After that, how do I open a new link to another page? – TIMEX Jul 02 '11 at 21:46
  • 1
    "open a new link to another page" > if you meant Pop-up, then inside the if block try another window.open, else u can use document.location = "http://New Location"; – Pheonix Jul 02 '11 at 21:49
1
$('#anchor').click(function(){

   if(!window.open()){
      //pop up failed.


     window.open('http://www.example.net/'); // open url in new tab
     window.location = "http://www.example.net/" // open in current window

   }

});
HoLyVieR
  • 10,985
  • 5
  • 42
  • 67
Kanishka Panamaldeniya
  • 17,302
  • 31
  • 123
  • 193