Check if popup is open

How can I change this so that it checks, and if the popup is already open?

function popUp(URL) { day = new Date(); id = day.getTime(); eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=350,height=100');"); } 

///////////// Edit No2

var options = "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=350,height=100";

var popup = window.open(URL, "popup", options);

function popUp(URL) { day = new Date(); id = day.getTime(); eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=350,height=100');"); }

My js call

<a id="floating_link" href="javascript:popUp('MyPage.html')">Player</a>

0
source share
2 answers

My answer to this related question here.

Check out the following code.

You can use onbeforeunload to get a callback before the window is unloaded.

To check if this is related to window.close do this

 setTimeout(function(){ if(anc.closed) console.log('closed'); else console.log('refreshed'); },1000); // to check after the window closed 

FULL CODE

 var anc = window.open('https://stackoverflow.com'); var anc.onbeforeunload = function() { // called before closing the window. setTimeout(function() { if (anc.closed) console.log('closed'); else console.log('refreshed'); }, 1000); // to check after the window closed } 
0
source

Use the same id for the window, which is the name of the window, for reuse if it exists.

http://www.w3schools.com/jsref/met_win_open.asp

 var options = "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=350,height=100"; var popup = window.open(URL, "popup", options); 

To do this with the anchor tag, you simply set target

If you set the target anchor tag target="myopup" , it will use the same window if it exists

+1
source

Source: https://habr.com/ru/post/917373/


All Articles