检查一个窗口是否已经被打开:
var myPage='js13.htm';
function openMyPage() {
if (!myPage || myPage.closed){
myPage =
window.open("13.htm", "_blank");
}
else {
alert("13.html is already opened");
}
}
</SCRIPT>
var myPage='js13.htm';
function openMyPage() {
if (!myPage || myPage.closed){
myPage =
window.open("13.htm", "_blank");
}
else {
alert("13.html is already opened");
}
}
</SCRIPT>
怎么设置啊?
如果为空 就不是c打开
如果不为空。再判断是不是c打开
alert(parent.main.window.opener);-->在B文件中(main为C文件位置IFRAME的name)
再请问,怎么捕抓到模式窗口的关闭?好象只有在用window.close()控制其关闭的时候,才能用下面命令捕抓得到:
if (event.clientX>document.body.clientWidth-20 && event.clientY<0||event.altKey)
window.event.returnValue="确定要退出吗?";
<script language=javascript>
var modalOpened = false;
var needOpen = false;
</script>2. any time you open a modal dialog, set the valuetop.modalOpened = true;
var ret = showModalDialog("modal.aspx",window);
top.modalOpened = false;3. if your page in B wants to open a modalDialog, settop.needOpen = true;then periodically check if top.modalOpened is false, if it is false, do top.needOpen = false;
top.modalOpened = true;
var ret = showModalDialog("modal.aspx",window);
top.modalOpened = false;4. in all pages which will be opened by showModalDialog, such as "modal.aspx", periodically check the value of window.dialogArguments.top.needOpen, if it is true, call window.close()
if (event.clientX>document.body.clientWidth &&event.clientY<0 || event.clientY<0 && event.clientX<20 || event.altKey|| event.clientY>document.body.clientHeight)
frameset.htm 框架文件,并定义一个global的变量做触发条件
refresh.htm 自动刷新的文件,相当于B文件
main.htm 主文件,相当于C文件
sub.htm 模式窗口文件,相当于D文件具体内容:
frameset.htm:
<html>
<script language=javascript>
var ii = 1; //在sub.htm中访问,在refresh.htm中设置
</script>
<frameset rows="100,*">
<frame src="refresh.htm">
<frame src="main.htm">
</frameset>
</html>refresh.htm:每2秒自动刷新
<html>
<head>
<meta http-equiv="Refresh" content="2;URL=refresh.htm">
</head>
<body>
<input type=text id=txt value="1">
<script language=javascript>
top.ii = 1; //设置global变量的值,请手动修改这个值
</script>
</body>
</html>main.htm:
<html>
<script language=javascript>
function OpenDialog()
{
showModalDialog("sub.htm", top);
}
</script>
<body>
<input type=button value="Open" onclick="OpenDialog()">
</body>
</html>sub.htm:
<html>
<script language=javascript>
setTimeout("GetInt()", 2000);
var iCount = 0;
function GetInt()
{
var t = document.getElementById("txt");
var win = window.dialogArguments;
iCount++;
t.value = iCount + ":" + win.ii;
setTimeout("GetInt()", 2000);
if (win.ii == 10)
{
window.close();
}
}
</script>
<body>
<input type=text id=txt>
</body>
</html>测试:
在IE中打开frameset.htm,点"Open"打开模式窗口,现在可以看到sub.htm中,能不断读取global变量的值。用记事本修改refresh.htm(修改top.ii=1这句,将1改成其他值),保存,等refresh.htm自动刷新后,可以看到sub.htm中能得到新的值。将top.ii=1改成top.ii=10,保存refresh.htm,等refresh.htm自动刷新后,sub.htm得到新的值为10,自动关闭自身