我想在打开弹出窗口之前检查弹出窗口是否已经打开。 我如何使用 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/