80分求一段js 我又两个页面a.htmb.htm点击a里边的链接,弹出b在a里边,怎么得到b的状态(开启/已关闭)js这种效果该怎么写 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 a:var bWin = window.open(b.htm);if(bWin.closed){ // b.htm窗口关闭了} a.html:<!DOCTYPE html><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Insert title here</title> </head> <body> <p>This is a.html</p> <a href="b.html" target="_blank" class="link">link</a> <script> function setNewPageStatus(boolean){ var link = document.getElementsByTagName('a')[0]; if(boolean){ var className = link.getAttribute('class'); className = className ? className + ' clicked' : 'clicked'; link.setAttribute('class', className); }else{ if(link.className === 'clicked'){ link.removeAttribute('className'); }else{ var className = link.getAttribute('class').replace(/ clicked|clicked /, ''); link.setAttribute('class', className); } } } function getNewPageStatus(){ var link = document.getElementsByTagName('a')[0], className = link.getAttribute('class'); return className.indexOf('clicked') === -1 ? false : true; } function alertNewPageStatus(){ alert(getNewPageStatus()); } </script> </body></html>b.html:<!DOCTYPE html><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Insert title here</title> </head> <body> <p>This is b.html</p> <script> window.onload = function(){ opener.setNewPageStatus(true); opener.alertNewPageStatus(); } window.onunload = function(){ opener.setNewPageStatus(false); opener.alertNewPageStatus(); } </script> </body></html> a.html:<!DOCTYPE html><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Insert title here</title> </head> <body> <p>This is a.html</p> <a href="b.html" target="_blank" class="link">link</a> <script> function checkNewPageStatus(windowObj){ if(windowObj.closed){ alert("窗口已关闭"); }else{ alert("窗口已打开"); } } </script> </body></html>b.html<!DOCTYPE html><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Insert title here</title> </head> <body> <p>This is b.html</p> <script> window.onload = function(){ opener.checkNewPageStatus(this); } window.onunload = function(){ opener.checkNewPageStatus(this); } </script> </body></html> 上面有点问题,蛋疼。。a.html:<!DOCTYPE html><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Insert title here</title> </head> <body> <p>This is a.html</p> <a href="b.html" target="_blank" class="link">link</a> <script> function checkNewPageStatus(windowObj){ setTimeout(function(){ if(windowObj.closed){ alert("窗口已关闭"); }else{ alert("窗口已打开"); } }, 100); } </script> </body></html>b.html:<!DOCTYPE html><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Insert title here</title> </head> <body> <p>This is b.html</p> <script> window.onload = function(){ opener.checkNewPageStatus(this); } window.onunload = function(){ opener.checkNewPageStatus(this); } </script> </body></html> window.parent.function(value)看你什么时候传 就什么时候调用父页面函数 1.在里面定义一个变量state var state = false;2.在弹出b窗口的时候,设置state=true3.在b窗口里面加入事件:window.onunload=function(){ opener.state = false;}取state就可以b的状态(开启/已关闭) jquery 给span赋值问题 点击切换一组图片., 怎么实现打开一个页面能控制他的大小 和 在显示屏的位置 iframe里面创建DIV JQUREY 急 在线等待!js问题 ff与IE下的window.event 在IE中好使但在firefox中不好使!!急 如何实现层的移动?急!!! 奇怪的问题 急求哪位大神帮我解决这个问题,其实挺容易,只是我不熟悉 javaScript代码多浏览器兼容(IE,Firefox等)
var bWin = window.open(b.htm);if(bWin.closed){
// b.htm窗口关闭了
}
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<p>This is a.html</p>
<a href="b.html" target="_blank" class="link">link</a>
<script>
function setNewPageStatus(boolean){
var link = document.getElementsByTagName('a')[0];
if(boolean){
var className = link.getAttribute('class');
className = className ? className + ' clicked' : 'clicked';
link.setAttribute('class', className);
}else{
if(link.className === 'clicked'){
link.removeAttribute('className');
}else{
var className = link.getAttribute('class').replace(/ clicked|clicked /, '');
link.setAttribute('class', className);
}
}
}
function getNewPageStatus(){
var link = document.getElementsByTagName('a')[0],
className = link.getAttribute('class');
return className.indexOf('clicked') === -1 ? false : true;
}
function alertNewPageStatus(){
alert(getNewPageStatus());
}
</script>
</body>
</html>
b.html:<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<p>This is b.html</p>
<script>
window.onload = function(){
opener.setNewPageStatus(true);
opener.alertNewPageStatus();
}
window.onunload = function(){
opener.setNewPageStatus(false);
opener.alertNewPageStatus();
}
</script>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<p>This is a.html</p>
<a href="b.html" target="_blank" class="link">link</a>
<script>
function checkNewPageStatus(windowObj){
if(windowObj.closed){
alert("窗口已关闭");
}else{
alert("窗口已打开");
}
}
</script>
</body>
</html>
b.html<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<p>This is b.html</p>
<script>
window.onload = function(){
opener.checkNewPageStatus(this);
}
window.onunload = function(){
opener.checkNewPageStatus(this);
}
</script>
</body>
</html>
a.html:<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<p>This is a.html</p>
<a href="b.html" target="_blank" class="link">link</a>
<script>
function checkNewPageStatus(windowObj){
setTimeout(function(){
if(windowObj.closed){
alert("窗口已关闭");
}else{
alert("窗口已打开");
}
}, 100);
}
</script>
</body>
</html>
b.html:<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<p>This is b.html</p>
<script>
window.onload = function(){
opener.checkNewPageStatus(this);
}
window.onunload = function(){
opener.checkNewPageStatus(this);
}
</script>
</body>
</html>
var state = false;2.在弹出b窗口的时候,设置state=true3.在b窗口里面加入事件:
window.onunload=function(){
opener.state = false;
}
取state就可以b的状态(开启/已关闭)