【问题标题】:How do I detect that my pop-up window failed (due to a pop-up blocker)? [duplicate]如何检测我的弹出窗口失败(由于弹出窗口阻止程序)? [复制]
【发布时间】:2011-07-02 21:38:40
【问题描述】:

可能重复:
How can I detect if a browser is blocking a popup?

我想在 Facebook (facebook.com/sharer.php) 上打开一个新窗口 (onclick)。

但是,如果由于弹出窗口阻塞而失败,我想检测它并将其更改为链接(新标签)。

我该怎么做?

【问题讨论】:

    标签: javascript jquery html css ajax


    【解决方案1】:
    if(!window.open()){
    //pop up failed.
    }
    

    【讨论】:

    • 之后,如何打开另一个页面的新链接?
    • "打开一个新链接到另一个页面" > 如果你的意思是弹出窗口,那么在 if 块内尝试另一个 window.open,否则你可以使用 document.location = "New Location" ;
    【解决方案2】:
    $('#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
    
       }
    
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-14
      • 1970-01-01
      • 1970-01-01
      • 2020-05-04
      相关资源
      最近更新 更多