History.back() – Problems With Chrome and Safari
Had a bit of an issue today with our old friend history.back(). This works fine in IE + FF:
<a href=”#” onclick=”history.back();”>Back</a>
But doesn’t seem to want to play in Chrome or Safari. So I tried to tidy up the code and be a little more strict:
<a href=”#” onclick=”window.history.back(-1);”>Back</a>
But still noy joy. In the end I went for this:
<script>
function goback() {
history.go(-1);
}
</script>
<a href=”javascript:goback()”>Back</a>
Which works across every browser, as far as I can tell.
Not sure if this is my error or a Chrome bug, but this is a useful workaround for me anyway. Hope it helps.
—————————————————————————————————————————————
You like?
Did you find this interesting or useful? Then maybe you could buy me a beer?
If you though it was rubbish or boring, then I’m sorry and you don’t need to bother.
















November 16th, 2009 at 6:04 pm
Thanks, dude! You’ve saved at least couple of my head kicking the wall :)
January 23rd, 2010 at 1:25 pm
Thank you very much! You solved my huge problem.
January 23rd, 2010 at 1:53 pm
Actually, I find this is not really working, and sometime, it broke.
January 25th, 2010 at 6:31 am
Hi Taiji,
What browser are you using? Which version?
This totally works for me.
June 2nd, 2010 at 6:28 pm
this code:
window.history.back(-1);
works for:
chrome 4.1
safari 4.0.5
ie 8
so what version of browser is it not working for you?
June 2nd, 2010 at 9:13 pm
Hi Simon,
When this article was written, we were on Chrome 2.1 and Firefox 3.0 (I think), and they were having the problems mentioned.
May well be that this is fixed now, not sure, haven’t come across it for a while.
July 16th, 2010 at 3:33 pm
window.back(); doesnt’t work in Chrome 5.0 but does in FireFox 3.6.6, IE7&8.
window.history.back(-1); works in them all.
Thanks to simon for this code!!
July 21st, 2010 at 1:47 pm
I had to use the original fix (the javascript function) on Chrome 5.0.375.99 on Vista 32.
None of the other methods would work here.
August 6th, 2010 at 1:11 pm
No funciona en Google Chrome 5
September 7th, 2010 at 5:49 am
Hi All,
i am using window .history.back() on my website and deployed it on linux server , the window.history.back() works fine on my local system but its is not working on the server. So do we need to make certain other arrangement for linux server on moving with history.back() oe there is any other workaround.
Kindly reply asap.
Regards
September 7th, 2010 at 5:41 pm
What browser are you using Satish?
This is a browser issue only, should not matter what server you are using.
Just remember when testing to actually visit some other pages first, before clicking the link to go back, otherwise you won’t have anywhere to go back to!