Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onclick="javascript:history.go(-1)" not working in Chrome

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?

like image 448
user961627 Avatar asked Apr 27 '13 14:04

user961627


People also ask

What is history Go (- 1?

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.

Why is my JavaScript code not working in Chrome?

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.

What is history length?

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.


1 Answers

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> 
like image 119
Mohit Padalia Avatar answered Oct 09 '22 03:10

Mohit Padalia