-3

I have the following JavaScript code:

 <text>Welcome <strong>@User.Identity.Name</strong>! </text>  
   <a href="javascript:window.opener='x';window.close();">[ Close ] </a> 

but it will not be able to force firefox browser to close it will only work for IE.

4

1 回答 1

2

根据 MDN

仅允许为使用 window.open 方法的脚本打开的窗口调用此方法。如果窗口不是由脚本打开的,JavaScript 控制台中会出现以下错误:

Scripts may not close windows that were not opened by script.

基本上,如果您没有通过 打开窗口window.open(),您将无法以编程方式关闭窗口。

于 2013-01-05T11:56:23.777 回答