在使用Jquery打开之前检查一个弹出窗口是否已经打开 [英] Check if a popup window is already open before opening it using Jquery
本文介绍了在使用Jquery打开之前检查一个弹出窗口是否已经打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查弹出窗口是否已经打开,然后打开弹出窗口。
如何使用Jquery完成它?
I want to check if a popup window is already open , before I open the popup window. How do I get it done using Jquery?
以下是我的代码,用于打开一个新的弹出窗口:
Below is my code to open a new popup window :
window.open("mystopchat.php?stat=1&session="+data['myid1']['session_id'][i],"win1","width=500,height=500");
现在,在我调用这个函数之前,我想确保这个弹出窗口尚未打开。 / p>
Now before I call this, I want to be sure that this popup window is not already open.
推荐答案
这是我使用的一个小技巧,也许您可以使用它:
This is a little trick I use, perhaps you could use it:
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();
}
}
}
希望它有帮助。
这篇关于在使用Jquery打开之前检查一个弹出窗口是否已经打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文