2011-05-27 87 views
2

我想關閉窗口。我的腳本在ie和firefox 2.x中工作正常,但在firefox 3.x及更高版本中無法正常工作。我正在使用以下腳本。關閉firefox中的窗口

function closeWindow() { 
    window.open('', '_self', ''); //bug fix 
    window.close();  
} 

請找到一些解決方案。 謝謝大家。

+2

請參閱討論[這裏](http://stackoverflow.com/questions/760422/how-can-i-close-a-window-與-JavaScript的上Mozilla的Firefox的-3)。簡短回答:您無法關閉未在Firefox中修復的JavaScript窗口。 – emfurry 2011-05-27 05:12:29

回答

0

window.open()返回一個對打開窗口的引用,你可以用它作爲close()。例如:

var win = window.open(url) 
win.close() 

Firefox(正確)不會讓您關閉您未打開的窗口。

1
function closeWindow() { 
      if (navigator.appName != "Microsoft Internet Explorer") { 
       netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite"); 
      } 
      alert("This will close the window"); 
      window.open('', '_self'); 
      window.close(); 
     } 

這是工作在兩個Firefox和IE

+1

不再適用於Firefox 8,但它確實修復了使用IE 8時的警告消息 – Alok 2011-12-09 18:03:08