根据history判断,有历史页就返回上一页,没有就关闭页面

//根据history判断,有历史页就返回上一页,没有就关闭页面
function
goBack(){ if ((navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Opera') < 0)){ // IE if(history.length > 0){ window.history.go( -1 ); }else{ 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.close() } }else{ //未知的浏览器 window.history.go( -1 ); } } }

 

 
posted on 2020-02-20 15:02  猪mother  阅读(743)  评论(0编辑  收藏  举报