如何修改它以便检查弹出窗口是否已打开?
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
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');");
}
我的js致电
<a id="floating_link" href="javascript:popUp('MyPage.html')">Player</a>
答案 0 :(得分:1)
对窗口使用相同的id
(窗口名称),以便在窗口存在时重复使用。
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);
要使用锚标记执行此操作,您只需设置target
如果您设置了锚标记的目标target="myopup"
,它将使用相同的窗口(如果存在)
答案 1 :(得分:0)
我的回答是this与此相关的问题。
检查以下代码。
您可以在卸载窗口之前使用onbeforeunload来获取回调。
检查这是否归因于window.close
执行此操作
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
}