admin管理员组文章数量:1279048
I have a simple sample page that I'm working on with a popup child popup window when you click on a link. I've been trying various unload events to close the child window when the parent is closed but cannot seem to figure out what I'm missing that ties into the simple coding.
The popup works flawlessly, however closing the parent window leaves the popup open.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ".dtd">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<a href='javascript:void(0);' onclick='window.open("/","pagename","width=800, height=800");' target='windowname'><font color="#70c7c8">Link Name</a>
</body>
</html>
I have a simple sample page that I'm working on with a popup child popup window when you click on a link. I've been trying various unload events to close the child window when the parent is closed but cannot seem to figure out what I'm missing that ties into the simple coding.
The popup works flawlessly, however closing the parent window leaves the popup open.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<a href='javascript:void(0);' onclick='window.open("http://example./files/foldername/","pagename","width=800, height=800");' target='windowname'><font color="#70c7c8">Link Name</a>
</body>
</html>
Share
Improve this question
edited Jul 13, 2014 at 21:43
user3518979
asked Jul 13, 2014 at 21:10
user3518979user3518979
772 silver badges7 bronze badges
1 Answer
Reset to default 10You're looking for window.onbeforeonload
:
<script>
var openPopup = function() {
var popupWindow = window.open("http://example.","pagename","width=800, height=800");
window.onbeforeunload = function() {
popupWindow.close();
};
}
</script>
<a href='javascript:void();' onclick='openPopup()'>Click to open a window...</a>
http://jsfiddle/LM35w/
(You have no idea how many times I closed the window to test it and lost track of the fiddle...)
本文标签: javascriptClosing Child (popup window) when Parent window is closedStack Overflow
版权声明:本文标题:javascript - Closing Child (popup window) when Parent window is closed - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741259038a2367248.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论