父页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> <script type="text/javascript"> function change(){ var cook=document.cookie.indexOf("secondtab=true"); if(cook==-1){ window.open("a.html"); }else{ alert("子页面已经存在"); } } </script> </head><body> <input type="button" onclick="change()"> </body> </html>子页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> <script type="text/javascript"> function init(){ document.cookie="secondtab=true;max-age=10000"; } function unb(){ document.cookie="secondtab=false;max-age=10000"; } window.onload=init; window.onunload=unb; </script> </head><body> </body> </html> 用cookie试试
从 A 页面弹出 B 页面后 B 页面会返回一个引用,只需要判断引用是否存在就行
获取不到b的引用了。。js没有那种方法
to zzgzzg00: cookie之前也试过的确可以,但js的window.onunload方法实在太不管用,页面刷新也会调用,还需自己判断点“X”关闭,ALT+F4,右键任务栏关闭。问题出在移动页面位置到屏幕最下面再右键任务栏关闭,这种情况,js就控制不到了,所以我才想有没有直接取得子窗口的方法。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function change(){
var cook=document.cookie.indexOf("secondtab=true");
if(cook==-1){
window.open("a.html");
}else{
alert("子页面已经存在");
}
}
</script>
</head><body>
<input type="button" onclick="change()">
</body>
</html>子页面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function init(){
document.cookie="secondtab=true;max-age=10000";
}
function unb(){
document.cookie="secondtab=false;max-age=10000";
}
window.onload=init;
window.onunload=unb;
</script>
</head><body>
</body>
</html>
用cookie试试
cookie之前也试过的确可以,但js的window.onunload方法实在太不管用,页面刷新也会调用,还需自己判断点“X”关闭,ALT+F4,右键任务栏关闭。问题出在移动页面位置到屏幕最下面再右键任务栏关闭,这种情况,js就控制不到了,所以我才想有没有直接取得子窗口的方法。