我有一个简单的示例页面,当您单击链接时,我正在处理一个弹出子弹出窗口。当父窗口关闭时,我一直在尝试各种卸载事件来关闭子窗口,但似乎找不出我在简单编码中缺少的是什么。
弹出操作完美,但是关闭父窗口会打开弹出窗口。
<!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=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<a href='javascript:void(0);' onclick='window.open("http://example.com/files/foldername/","pagename","width=800, height=800");' target='windowname'><font color="#70c7c8">Link Name</a>
</body>
</html>发布于 2014-07-13 21:54:54
你在找window.onbeforeonload
<script>
var openPopup = function() {
var popupWindow = window.open("http://example.com","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.net/LM35w/
(你不知道我关了多少次窗来测试它,失去了小提琴的踪迹.)
https://stackoverflow.com/questions/24727036
复制相似问题