我又两个页面
a.htm
b.htm点击a里边的链接,弹出b
在a里边,怎么得到b的状态(开启/已关闭)js这种效果该怎么写
a.htm
b.htm点击a里边的链接,弹出b
在a里边,怎么得到b的状态(开启/已关闭)js这种效果该怎么写
解决方案 »
- 关于浏览器的兼容问题?
- js:怎么从父窗口弹模态窗口ASP.NET
- 为什么加了DOCTYPE声明,这段代码就没用了
- 关于js函数参数传递问题
- BEA中国公司 招聘实习生(欢迎广大同学报名)
- 请行家指教:JavaScript做的导航菜单,出现页面抖动?
- 【求帮助】window.event.returnvalue=false;不起作用
- 表格的动态删除行,一个小问题,来者有分!
- 关于Session END 在什么情况下会引起Session_End(来者有分)
- 这句a = {"a" : "Athens" , "b" : "Belgrade", "c" : "Cairo"}怎样理解???
- 急求哪位大神帮我解决这个问题,其实挺容易,只是我不熟悉
- 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的状态(开启/已关闭)