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

后端 未结 5 998
野趣味
野趣味 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 01:03

    Window.open(...) returns a handle to the new window if it exists. If it doesn't have a handle to the new window, that's a pretty good indication the window was blocked.

    https://developer.mozilla.org/en-US/docs/Web/API/Window/open

    From: https://davidwalsh.name/popup-block-javascript

    var windowName = 'userConsole'; 
    var popUp = window.open('/popup-page.php', windowName, 'width=1000, height=700, left=24, top=24, scrollbars, resizable');
    if (popUp == null || typeof(popUp)=='undefined') {  
        alert('Please disable your pop-up blocker and click the "Open" link again.'); 
    } 
    else {  
        popUp.focus();
    }
    

提交回复
热议问题