因浏览器目前使用情况各种各样,标准不一。下面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();
}
}