javascript - 按钮 onclick 删除另一个浏览器窗口

标签 javascript html window intervals

我有两个网页。 首先.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/

相关文章:

PHP echo 返回确认函数斜杠

html - 在 HTML 中使用 CSS 选择器

html - 使用 AngularJS 在 HTML 中添加换行符

android - 超时后删除android窗口

c# - 当 showdialogwindow 阻止我尝试访问的窗口时,是否有事件或我可以使用的东西

javascript - 如何并行运行生成器函数?

javascript - 第一个滚动脚本之后的 fullpage.js

javascript - Python Django 元素 - 将 div 类页脚移动到正文中

javascript - 如何在图像 map 上创建一个 html 工具提示?

C++ Qt 窗口定位