前端——js關閉頁面方法

js關閉當前頁面,當該頁面不是其餘頁面打開的,而是直接輸入url,瀏覽器

直接用window.close()沒法關閉。url

如下代碼能夠實現不一樣瀏覽器的關閉操做:io

function CloseWebPage(){ if (navigator.userAgent.indexOf("Firefox") != -1 || navigator.userAgent.indexOf("Chrome") !=-1) {
window.location.href="about:blank";
window.close();
} else {
window.opener = null;
window.open("", "_self");
window.close();
}
}function

function CloseWebPage(){ if (navigator.userAgent.indexOf("MSIE") > 0) { if (navigator.userAgent.indexOf("MSIE 6.0") > 0) { window.opener = null; window.close(); } else { window.open('', '_top'); window.top.close(); } } else if (navigator.userAgent.indexOf("Firefox") > 0) { window.location.href = 'about:blank '; } else { window.opener = null; window.open('', '_self', ''); window.close(); } }top

相關文章
相關標籤/搜索