因瀏覽器目前使用狀況各類各樣,標準不一。下面js是一個通用化的腳本。使用JavaScript關閉瀏覽器的窗口或頁籤。瀏覽器
function closeWebPage() { if (navigator.userAgent.indexOf("MSIE") > 0) { // IE if (navigator.userAgent.indexOf("MSIE 6.0") > 0) {// IE6 window.opener = null; window.close(); } else {// IE6+ window.open('', '_top'); window.top.close(); } } else if (navigator.userAgent.indexOf("Firefox") > 0 || navigator.userAgent.indexOf("Presto") > 0) {// FF和Opera window.location.href = 'about:blank'; window.close();// 火狐默認狀態非window.open的頁面window.close是無效的 } else { window.opener = null; window.open('', '_self', ''); window.close(); } }