Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Page history - back button exists?

Tags:

javascript

Is it possible check if there is a value for history.go(-1)? I know you can't access history.previous directly.

I am trying to stay away from document.referrer because I know it can be blocked in some instances.

Here is what I am trying to do. I have an error page, on this page I would like to either have a BACK button (if it's not the only item in history) or a close button (if it is).

like image 252
Louis W Avatar asked Jun 11 '09 16:06

Louis W


People also ask

What does history back return?

back() The History. back() method causes the browser to move back one page in the session history. It has the same effect as calling history.go(-1) .

What button is used to go back a page?

Left side button is used by default to go back in a page like for example in browsing to go back to previous page.

Can I use history back ()?

back() is the same as history.go(-1) . history. back() is the same as clicking "Back" your browser.

How do you check if the user can go back in browser history or not?

You can't directly check whether the back button is usable. You can look at history. length>0 , but that will hold true if there are pages ahead of the current page as well. You can only be sure that the back button is unusable when history.


1 Answers

if (history.length) {
    //There is history to go back to
    history.go(-1);
}    
like image 89
Andreas Grech Avatar answered Nov 17 '22 04:11

Andreas Grech