I'm building an application in an environment where I'm restricted to using the local file system and a browser (i.e. running a server isn't an option). I have a generic 'go back' link on numerous pages that mainly just calls history.back()
. It looks something like the following:
function goBack(evt) {
// Check to see if override is needed here
// If no override needed, call history.back()
history.back();
}
$('#my-back-button').click(goBack);
This code works fine in Firefox and IE6 (don't ask), but fails in Chrome. Any suggestions as to why and/or possible workarounds?
I've also tried history.go(-1);
which does not work either.
back() is the same as history.go(-1) . history. back() is the same as clicking "Back" your browser.
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.
To check if the user can go back in browser history or not with JavaScript, we can call history. back or history.go . history.go(-1); to go back to the previous page.
A back button in the browser lets you back-up to the copies of pages you visited previously. The web browser's back and next buttons work well with web sites that provide information that changes infrequently, such as news and shopping web sites.
For some reason in chrome, you have to add return false after calling history.go(-1)
Change your function to:
function goBack(evt) {
// Check to see if override is needed here
// If no override needed, call history.back()
history.go(-1);
return false;
}
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