<html>
<head>
<script language="javascript">
<!--
function openWin(strURL) {
var x, y, wx, wy;
if (!gfSubWinCheck(strURL)) {
return false;
}
gobjSubWin=window.open(strURL,'',"dialogHeight:234px;dialogWidth:271px;resizable:no;help:yes;status:no;scroll:no");
} if (gobjSubWin==null) var gobjSubWin = 0; function gfSubWinCheck(strURL) {
if(gobjSubWin == 0) {
return true;
}else if( gobjSubWin.closed ) {
alert('it was Closed,i\'ll open a new one.');
return true;
}else {
alert('it was existed.');
gobjSubWin.focus();
return false;
}
}
//-->
</SCRIPT>
</script></head><body>
<INPUT TYPE="button" value="openwin" onclick="openWin('http://www.sina.com.cn')">
</body></html>
<head>
<script language="javascript">
<!--
function openWin(strURL) {
var x, y, wx, wy;
if (!gfSubWinCheck(strURL)) {
return false;
}
gobjSubWin=window.open(strURL,'',"dialogHeight:234px;dialogWidth:271px;resizable:no;help:yes;status:no;scroll:no");
} if (gobjSubWin==null) var gobjSubWin = 0; function gfSubWinCheck(strURL) {
if(gobjSubWin == 0) {
return true;
}else if( gobjSubWin.closed ) {
alert('it was Closed,i\'ll open a new one.');
return true;
}else {
alert('it was existed.');
gobjSubWin.focus();
return false;
}
}
//-->
</SCRIPT>
</script></head><body>
<INPUT TYPE="button" value="openwin" onclick="openWin('http://www.sina.com.cn')">
</body></html>
但是现在我的窗口有参数,比如:www.sina.com.cn?area=1(或者2,3,4,5),target设为1,2,3,4,5
这样就存在5个窗口。上面的代码只能检测www.sina.com.cn,对于有参数不起作用。
然后根据编号来判断是否存在。
function a(u,t)
{
window.open(u+t,"w"+t)
}
a("http://www.sina.com.cn?area=",1)
a("http://www.sina.com.cn?area=",2)
a("http://www.sina.com.cn?area=",3)
</script>
我在main.aspx中打开sendmsg.aspx?id=1.,三秒钟后main.aspx要再次检测sendmsg.aspx?id=1这个窗口是否打开了,如果打开了,就不做任何动作,如果没有,就开这个窗口。
下面是dreamweaver自带的打开窗口的例子:
var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{
if(popUpWin)
{
if(!popUpWin.closed) popUpWin.close();
}
popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}
我调用该方法时,无论ID=多少,js似乎只认识sendmsg.aspx.
fantiny说的“gobjSubWin = 编号”,gobjSubWin是打开窗口,可以用编号赋值吗?
望解答,在线等待。
<script>
var popUpWin=new Array();
function popUpWindow(URLStr,ID)
{
var left=200;
var height=200;
var top=20;
var width=300;
if(popUpWin[ID])
{
if(!popUpWin[ID].closed) alert('编号为'+ID+'的窗口处于打开状态');
else
popUpWin[ID] = open(URLStr+ID, ID, 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}
else {
popUpWin[ID] = open(URLStr+ID, ID, 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}
}
</script><input type="text" value="http://localhost/chat/sendmsg.aspx?FriendID=" size=53 id="urlOpen">
<input type="text" value="1" size="10" id="FriendID">
<INPUT TYPE="button" value="openwin" onclick="popUpWindow(document.all.urlOpen.value,document.all.FriendID.value)">我把var型改成了Array型的,呵呵。总是想着参数,忘记了打开窗口用不同的变量保存了。
谢谢