2

我正在尝试通过单击按钮关闭当前窗口。我知道 window.close() 只能在窗口由 javascript 拥有时才能工作。


所以我以前用过window.open(),然后像这样关闭那个窗口:

self.name = "close";
window.open("","close");
self.opener = null;
self.close();`

这适用于 Chrome 和旧版本的 Firefox,但不适用于 FF14。那么如何在FF14中关闭一个窗口呢?谢谢!

我在 FF 控制台中运行以下 javascript。它适用于 IE 和 Chrome。

win=window.open('','_self');
win.close();------undefined
4

1 回答 1

-1

上面提到的注释是正确的 window.close() 只有在使用 window.open() 打开窗口时才会起作用。

试试这个代码:

<a href="#" onclick="javascript:var win = window.open('', '_self');win.close();return false;">Close</a>

这在 IE、Chrome 和 Firefox 中对我有用(甚至适用于 FF14)。高温高压

于 2012-08-08T11:52:27.290 回答