简体   繁体   English

从浏览器历史记录中关闭窗口

[英]Close window from browser history

I am working on a web application where I am using JavaScript for the client side scripting. 我正在使用Web客户端脚本编写Web应用程序。 Now my requirement is to close all the opened window which were opened through window.showModalDialog() . 现在,我的要求是关闭所有通过window.showModalDialog()打开的打开的窗口。

For this, I read the history of the browser using window.history.length , but I do not know how to close each window. 为此,我使用window.history.length读取了浏览器的历史记录,但是我不知道如何关闭每个窗口。 This works well for window.open() , but not for window.showModalDialog() . 这对于window.open()效果很好,但对于window.showModalDialog()效果不好。

Could you please guide me to move forward? 你能指导我前进吗?

You can close the opened window as follows: 您可以关闭打开的窗口,如下所示:

To Open: 打开:

var window1=window.open("http://somedomain.com");
var window2=window.open("http://someotherdomain.com");

To Close 关闭

window1.close();

window2.close();

But be sure you call window1.close() and so on.. on the same script where you opened it. 但是请确保在打开它的同一脚本上调用window1.close()等等。

You should not be using window.showModalDialog . 您不应该使用window.showModalDialog Firefox has deprecated it , and Chrome has removed it . Firefox已弃用它 ,而Chrome已将其删除 Also take a look at window.showModalDialog: What It is and Why You Should Never Use It . 还可以看看window.showModalDialog:它是什么以及为什么不应该使用它

The idea of showModalDialog is that all scripts are paused while the modal window is open. showModalDialog的想法是在模式窗口打开时暂停所有脚本。 Thus, using window.close doesn't work, since as long as the window is open, no more scripts are being executed. 因此,使用window.close不起作用,因为只要打开窗口,就不再执行任何脚本。

One possibility is to have JavaScript in the modal dialog so that is closes itself . 一种可能是在模式对话框中包含JavaScript,以使其自身关闭。 You will not be able to close it from outside. 您将无法从外部关闭它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM