要求:
问题:
浏览器重新呈现窗口时,由于F5/刷新按钮或导航,无法在页面上保留子窗口句柄。
发布于 2015-05-28 18:20:21
解决方案:
//Open popup window "ChildWinName1" from here
window.open("SomeSite/SomeApp/SomePage", "ChildWinName1", "width=600, height=400");
localStorage.setItem("Key1", "ChildWinName1");
//Open popup window "ChildWinName1" from here
window.open("SomeSite/SomeApp/SomePage", "ChildWinName2", "width=600, height=400");
localStorage.setItem("Key2", "ChildWinName2");
页面: BlankClose
<!DOCTYPE html>
<html>
<head>
<title>IndexX</title>
<script type="text/javascript">
function Exit() {
self.close();
}
this.Exit();
</script>
</head>
<body>
<div>
Bye..............
</div>
</body>
</html>
function closeAllChildWindow() {
var wins = localStorage.length
for (var i = 1; i <= wins; i++) {
var winName = localStorage.getItem("ChildWinName" + i.toString());
if (winName != null) {
window.open('/SomeSite/SomeApp/blankClose", "Home")', winName);
localStorage.removeItem("ChildWinName" + i.toString())
}
else {
if (localStorage.length > 0) wins++;
}
}
}
备注:可以使用JSON对象来封装字符串集合,而不是在本地存储中有多个键。
https://stackoverflow.com/questions/30514256
复制相似问题