2009-02-18 71 views

回答

9

你打開窗口使用window.openAccording to the docs on window.close

此方法只允許爲使用window.open方法由腳本打開的窗口調用。如果該窗口未被腳本打開,則JavaScript控制檯中會顯示以下錯誤:腳本可能無法關閉未由腳本打開的窗口。

0

嘗試使用window.close()來代替。

+1

這不是工作在Firefox – 2013-07-16 08:24:31

+0

不工作的Mozilla Firefox瀏覽器 – 2015-08-31 12:04:56

0

看到我的回答this other question。您應該能夠輕鬆地將它從ASP.NET調整爲純HTML。

基本上,因爲Mozilla瀏覽器只會讓你關閉被JS開了一個窗口,你可以打開一個新的窗口和目標_self:

window.open('close.html', '_self', null); 

現在您的窗口是通過JS打開,可以將其關閉與js! :) close.html:

<html><head> 
<title></title> 
<script language="javascript" type="text/javascript"> 
    var redirectTimerId = 0; 
    function closeWindow() 
    { 
     window.opener = top; 
     redirectTimerId = window.setTimeout('redirect()', 2000); 
     window.close(); 
    } 

    function stopRedirect() 
    { 
     window.clearTimeout(redirectTimerId); 
    } 

    function redirect() 
    { 
     window.location = 'default.aspx'; 
    } 
</script> 
</head> 
<body onload="closeWindow()" onunload="stopRedirect()" style=""> 
    <center><h1>Please Wait...</h1></center> 
</body></html> 
相關問題