Got a window.history.go(1)
to stop the user hitting the back button, but was wondering if I could check to see if a forward history exists before doing it, so I can display a popup warning the user not to press the back button.
I know you can get the history length, but is there a way to get the current position in the history list? Or some other way of doing this...
history object allows you to access the history stack of the browser. To navigate to a URL in the history, you use the back() , forward() , and go() methods. The history. length returns the number of URLs in the history stack.
forward() method causes the browser to move forward one page in the session history. It has the same effect as calling history.go(1) . This method is asynchronous. Add a listener for the popstate event in order to determine when the navigation has completed.
The History back() method in HTML is used to load the previous URL in the history list. It has the same practical application as the back button in our web browsers. This method will not work if the previous page does not exist. This method does not contain any parameter.
AFAIK you won't be able to access the history from JavaScript. It will be a security hole and most of the browsers won't allow that. Probably there might be a workaround in IE by using ActiveX.
Found this entry which might be useful to you
window.history
There is a next property.
Returns the URL of the next item in the session history This property is not available to web content and is not supported by other browsers.
For security reasons the History object doesn't allow the non-privileged code to access the URLs of other pages in the session history, but it does allow it to navigate the session history.
There is no way to clear the session history or to disable the back/forward navigation from unprivileged code. The closest available solution is the location.replace() method, which replaces the current item of the session history with the provided URL.
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