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).
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) .
Left side button is used by default to go back in a page like for example in browsing to go back to previous page.
back() is the same as history.go(-1) . history. back() is the same as clicking "Back" your browser.
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.
if (history.length) {
//There is history to go back to
history.go(-1);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With