window.close ();在firefox中不工作

window.close(); not working in firefox

本文关键字:firefox 工作 close window      更新时间:2023-09-26

单击关闭后,button当前窗口在Firefox中未关闭,但在IE中工作正常

function closeWin() {
    var d=window.opener;
    try {
        var param="";
        var winHref=d.document.location.href;
        if(winHref.indexOf("?") > -1){
    	    param=winHref.substr(winHref.indexOf("?"));
        }
        //d.document.location.href=d.document.forms[0].thankyouurl.value+'?'+param;
        d.document.location.href=d.document.getElementsByName('thankyouurl')[0].value+'?'+param;
    }
    catch(e){}
    finally{}
    window.close();
    return true;
}
<input type="button" name="Button" value="Close" onClick="return closeWin();">

在Firefox中不能使用window.close()关闭页面,除非使用脚本打开。所以你必须欺骗Firefox,让它以为你是用脚本打开它的。

function closeWindow() { 
  window.open('','_parent',''); 
  window.close(); 
}

现在只要在你想要关闭窗口的时候调用closeWindow()。