views:

36

answers:

2

So I thought this script was pretty straight forward:

<a id="BackButtonlnk" href="#" class="white" onClick="history.go(-1)"></a>

When I click it it briefly shows the previous page but just looks like it refreshes and you never end up at the previous page.

+3  A: 

Try adding "; return false" to your onclick.

I think what's happening is the onclick fires (trying to go to the previous page), and then the browser tries to go to "(current page)#" (note the "#"), and essentially refreshes the original page. Thus, it appears that it's going back and forth - because it is.

<a id="BackButtonlnk" href="#" class="white" onClick="history.go(-1); return false;"></a>
Ryan Kinal
Oh okay thanks I'll give it a shot.
Bry4n
Thank you very much!
Bry4n
+1  A: 

Try using the href instead of the onclick event:

<a id="BackButtonlnk" class="white" href="javascript:history.go(-1);">Go Back</a>
Jose Basilio
This is a perfectly workable solution as well. I just prefer to give the href a good URL, in case users have JavaScript turned off.
Ryan Kinal