This code works fine in FF, it takes the user back to the previous page, but not in Chrome:
<a href="www.mypage.com" onclick="javascript:history.go(-1)"> Link </a>
What's the fix?
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) . If there is no previous page, this method call does nothing. This method is asynchronous.
Google ChromeIn the "Settings" section click on the "Show advanced settings..." Under the the "Privacy" click on the "Content settings...". When the dialog window opens, look for the "JavaScript" section and select "Allow all sites to run JavaScript (recommended)". Click on the "OK" button to close it.
The History length property in HTML is used to return the count of URLs in the history list of the current browser window. The minimum value returned by this property is 1 because the current page is loaded at the moment whereas the maximum count that can be displayed in 50.
You should use window.history
and return a false so that the href
is not navigated by the browser ( the default behavior ).
<a href="www.mypage.com" onclick="window.history.go(-1); return false;"> Link </a>
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