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

时间:2015-08-13 07:17:10

标签: javascript html firefox

点击关闭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();">
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:5)

除非由脚本打开,否则您无法在Firefox中使用window.close()关闭该页面。因此,您必须欺骗Firefox,以为您使用脚本打开它。这可行:

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

现在只要你想关闭窗口就调用closeWindow()。这也适用于其他浏览器。

相关问题