Check if a popup window is already open before opening it using Jquery

前端 未结 5 1311
广开言路
广开言路 2021-02-08 11:44

I want to check if a popup window is already open , before I open the popup window. How do I get it done using Jquery?

Below is my code to open a new popup window :

5条回答
  •  囚心锁ツ
    2021-02-08 12:25

    Here is my suggestion:

    function authorize(callback) {
    
    if(!document.authorize) {
        console.log('Opening authorization window...');
        document.authorize = window.open('popup.html','tw','width=300,height=200');
    }
    
    if(document.authorize.closed) {
        console.log('Authorization window was closed...');
        setTimeout(callback,0); 
    } else {
        setTimeout(function(){
            console.log('Authorization window still open...');
            authorize(callback);
        },1000);    
    }
    
    return false;
    }
    
    
    function test() {
        authorize(function(){
          alert('teste');
        });
    }
    

提交回复
热议问题