gpt4 book ai didi

javascript - 在使用 Jquery 打开弹出窗口之前检查它是否已经打开

转载 作者:太空狗 更新时间:2023-10-29 13:24:08 25 4
gpt4 key购买 nike

我想在打开弹出窗口之前检查弹出窗口是否已经打开。我如何使用 Jquery 完成它?

下面是我打开一个新弹出窗口的代码:

window.open("mystopchat.php?stat=1&session="+data['myid1']['session_id'][i],"win1","width=500,height=500"); 

在我调用它之前,我想确定这个弹出窗口还没有打开。

最佳答案

这是我使用的一个小技巧,也许你可以使用它:

var winRef; //This holds the reference to your page, to see later it is open or not

function openWindow() {
var url = //Your URL;
if (typeof (winRef) == 'undefined' || winRef.closed) {
//create new, since none is open
winRef = window.open(url, "_blank");
}
else {
try {
winRef.document; //if this throws an exception then we have no access to the child window - probably domain change so we open a new window
}
catch (e) {
winRef = window.open(url, "_blank");
}

//IE doesn't allow focus, so I close it and open a new one
if (navigator.appName == 'Microsoft Internet Explorer') {
winRef.close();
winRef = window.open(url, "_blank");
}
else {
//give it focus for a better user experience
winRef.focus();
}
}
}

希望对您有所帮助。

关于javascript - 在使用 Jquery 打开弹出窗口之前检查它是否已经打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10882112/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com