Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using javascript history.back() fails in Safari .. how do I make it cross-browser?

Tags:

I am using

<a href="index.php" onclick="history.back();return false;">Back</a> 

to provide a back to previous page link. It works fine on Windows (IE/Mozilla) but fails in Safari on both Windows/Mac.

Is there a way to make it work on all of the systems/browsers (cross-browser/platform)?

If it's not possible, is there any other way using PHP etc?

like image 850
user187580 Avatar asked Dec 09 '09 11:12

user187580


2 Answers

it should be history.go(-1); return false; or history.go(-1); event.preventDefault();

like image 132
Robert Cabri Avatar answered Oct 05 '22 05:10

Robert Cabri


You should consider doing it like this instead:

<a href="javascript:history.go(-1)">Back</a> 
like image 34
Klaus Byskov Pedersen Avatar answered Oct 05 '22 06:10

Klaus Byskov Pedersen