检查弹出窗口是否已打开 [英] Check if popup window is already open
问题描述
如何修改它以便检查弹出窗口是否已打开?
How can I modify this so it checks and if a popup window 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');");
}
///////// ////编辑No2
/////////////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,可调整大小) = 1,宽度= 350,高度= 100' ););
}
我的js电话
My js call
< a id =floating_linkhref =javascript:popUp('MyPage.html')>播放器< / a>
推荐答案
我的回答是这个问题链接到这里。
My answer is to this question linked to here.
检查以下代码。
您可以使用 onbeforeunload 进行回电在窗口卸载之前。
You can use onbeforeunload to get a callback before the window unloads.
检查这是否是由于 window.close
执行此操作
To check if this is due to window.close
do this
setTimeout(function(){
if(anc.closed) console.log('closed');
else console.log('refreshed');
},1000); // to check after the window closed
完整代码
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
}
这篇关于检查弹出窗口是否已打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!