<html>
<head>
</head>
<body>
<button onclick="openNew('b.html')">1</button>
<input type="button" value="关闭子窗口" onclick="logOut()">
<script>
var win_Array = [];
let newWindow
// open窗口事件
function openNew(uri, param) {
newWindow = window.open(uri, param)
let is = win_Array.some(item => item.name === param)
win_Array.push({ name: param, newWindow });
}
function closeNews(win) {
if (win.length > 0) {
for (var i = 0; i < win.length; i++) {
win[i].newWindow.close()
}
}
}
// 关闭窗口事件
function logOut() {
win_Array.map(item => {
item.newWindow.postMessage({
close: true
})
})
closeNews(win_Array);
}
</script>
</body>
</html>
JS关闭所有的子窗口
于 2022-06-22 14:16:05 首次发布