Javascript:关闭弹出窗口

发布于 2025-01-03 06:58:23 字数 115 浏览 3 评论 0原文

我在主页上有一个按钮,它将打开 (window.open()) 窗口 W1 以允许用户在其上选择内容。之后,用户按 W1 上的 OK 按钮打开窗口 W2(再次 window.open())。用户按确定后如何关闭W1?

I have a button on the main page, which will open (window.open()) a window W1 to allow user to select stuff on it. After that, user press OK button on the W1 to open window W2 (again window.open()). How can i close the W1 after the user press OK?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光匆匆的小流年 2025-01-10 06:58:24

使用带有目标窗口名称的 window.close() 方法,如下所示:

win1 = window.open("","","width=100,height=100");
okBtn.onclick = function() {
    win2 = window.open("","","width=100,height=100");
    win1.close();
}

Use the window.close() method with the name of the target window as shown below:

win1 = window.open("","","width=100,height=100");
okBtn.onclick = function() {
    win2 = window.open("","","width=100,height=100");
    win1.close();
}
深空失忆 2025-01-10 06:58:24

在主页上,您将弹出窗口保存到 W1 中,并定义一个将关闭 W1 的函数:

W1 = window.open("","","width=100,height=100");

function closeW1() {
    W1.close();
}

现在在 W1 上打开 W2 的同一位置:

okBtn.onclick = function() {
    W2 = window.open("","","width=100,height=100");
    window.opener.closeW1();
}

就是这样。你完成了。

On the main page you save popup into W1 and define a function that will close W1:

W1 = window.open("","","width=100,height=100");

function closeW1() {
    W1.close();
}

Now on W1 in the same place where you open W2:

okBtn.onclick = function() {
    W2 = window.open("","","width=100,height=100");
    window.opener.closeW1();
}

That's it. You're done.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文