如何检测弹出窗口失败(由于弹出窗口阻止程序)?(复制)

时间:2022-02-19 20:42:23

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).

我想打开一个新窗口(onclick)到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).

但是,如果由于弹出阻塞而失败,我希望检测它并将其更改为一个链接(new tab)。

How can I do that?

我怎么做呢?

2 个解决方案

#1


3  

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

#2


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

   }

});

#1


3  

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

#2


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

   }

});