我有两个网页。 首先.html:
<script> window.onload = function(){ setTimeout(loadAfterTime, 3000) }; function loadAfterTime() { my_window = window.open("Second.html", "","status=1,width=100%,height=100%");}
this.window = previous_window ;
</script>
第二个.html:
<html>
<head>
<script>
function closepopup()
{
if(false == previous_window.closed)
{
previous_window.close ();
}
else
{
alert('Window already closed!');
}
}
</script>
</head>
<body>
<button onclick="closepopup();">
Close
</button>
</body>
</html>
如果我们在浏览器中加载 first.html,加载 3 秒后,JavaScript 将生成一个浏览器窗口,其中的 URL 设置为 Second.html。
我在 second.html 文件中添加了一个按钮。
如果我们按下那个按钮,我想删除/删除以前的浏览器窗口 (first.html)。
window.open
正在工作按钮 window.close
不是。
请帮忙。
此外,该代码应该可以在移动设备上完美运行(Android 和 IOS 上的最新 Chrome 应用程序)。
任何帮助将不胜感激。
最佳答案
First.html
<script>
window.onload = setTimeout(loadAfterTime, 3000);
function loadAfterTime()
{
window.open("Second.html","","status=1,width=100%,height=100%");
}
</script>
Second.html
<html>
<head>
<script>
function closepopup()
{
if(window.opener)
{
window.opener.close();
}
else
{
alert("Window already closed!");
}
}
</script>
</head>
<body>
<button onclick="closepopup();">Close</button>
</body>
</html>
关于javascript - 按钮 onclick 删除另一个浏览器窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47206125/