When working on a web project, we encounter a requirement. When the page has no predecessor history (that is, it is the page that is currently a newly popped up, and the goback operation cannot be performed (-1)), and then the page is closed directly when clicking the return button, otherwise it will return to the previous page.
The problem encountered is how to judge whether history can fall back. This is very troublesome, because there is no such function that can be directly obtained, and it can only be processed through this variable. However, for IE, the return value of length is different from that of non-IE. IE: =0, non-IE is 1, so a function was written to implement the function required before. Share with everyone.
/** * Return to the previous page (or close this page) * <li>If there is no history on the previous page, close the current page directly</li> */ function goBack(){ if ((('MSIE') >= 0) && (('Opera') < 0)){ // IE if( > 0){ ( -1 ); }else{ =null;(); } }else{ //Not IE browserif (('Firefox') >= 0 || ('Opera') >= 0 || ('Safari') >= 0 || ('Chrome') >= 0 || ('WebKit') >= 0){ if( > 1){ ( -1 ); }else{ =null;(); } }else{ //Unknown browser( -1 ); } } }