js判断有上一页就返回上一页,没上一页就关闭当前窗口
解决方法:
goBack() {
if ((navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Opera') < 0)) { // IE
if (history.length > 0) {
window.history.go(-1);
} else {
window.opener = null;
window.close();
}
} else { //非IE浏览器
if (navigator.userAgent.indexOf('Firefox') >= 0 ||
navigator.userAgent.indexOf('Opera') >= 0 ||
navigator.userAgent.indexOf('Safari') >= 0 ||
navigator.userAgent.indexOf('Chrome') >= 0 ||
navigator.userAgent.indexOf('WebKit') >= 0) {
if (window.history.length > 1) {
window.history.go(-1);
} else {
window.opener = null;
window.close();
}
} else { //未知的浏览器
window.history.go(-1);
}
}
}