1. 程式人生 > >chrome close js 關閉當前頁面

chrome close js 關閉當前頁面

Chrome瀏覽器如何呼叫js關閉當前頁面

Ext.Ajax.request({
        url: "Logout.aspx",
        params: {
            tag: "logout"
        },
        success: function () {
            var browserName = navigator.appName;
            if (browserName == "Netscape") {
                window.location.href = "about:blank";                    //關鍵是這句話
                window.close();
            } else if (browserName == "Microsoft Internet Explorer") {
                window.opener = null;
                window.close();
            }
        }
    });

在Chrome中,必須指定 window.location.href = "about:blank"; 

然後才呼叫close()方法.否則瀏覽器會提示:

VM408:1 Scripts may close only the windows that were opened by it.