Pop up blocker API- how to check if user has it enabled

后端 未结 5 997
野趣味
野趣味 2021-02-04 00:37

I need to know when the user clicks on the button that triggers window.open if there is stable API/way to know beforehand if the user actively has

5条回答
  •  天涯浪人
    2021-02-04 00:46

    Use this code to check

    var popupBlockerChecker = {check:function(b) {
    var a = this;
    b ? /chrome/.test(navigator.userAgent.toLowerCase()) ? setTimeout(function()      {
    a._is_popup_blocked(a, b);
    }, 200) : b.onload = function() {
    a._is_popup_blocked(a, b);
    } : a._displayError();
    }, _is_popup_blocked:function(b, a) {
    0 == 0 < a.innerHeight && b._displayError();
    }, _displayError:function() {
    alert("Popup Blocker is enabled! Please add this site to your exception list.");
    }};
    

    and the usage will be something like

     var popup = window.open("http://www.google.com.au", '_blank');
     popupBlockerChecker.check(popup);
    

提交回复
热议问题