How to window.back() and window.forward()

This code won't work.  What am I doing wrong? I want to click one image to page back and another to page forward. (I don't want to use form buttons.)

<a HREF="#" onClick="window.back()">
<img src="images/back01.jpg"></a>

<a HREF="#" onClick="window.forward()">
<img src="images/for01.jpg"></a>
Who is Participating?
martinagConnect With a Mentor Commented:
You've written onMouseOver and onMouseOut as their own tags when they in fact are attributes to the <A> tag:
<a HREF="javascript:history.back()" onMouseOver="act('back');window.status='Back';return true" onMouseOut="inact('back');window.status=' ';return true">

Use history, not window:

I'd use BORDER="0" for the images. Also, I recommend to put the code in the HREF instead of onClick:

<a HREF="javascript:history.back()"><img src="images/back01.jpg" border="0"></a>
<a HREF="javascript:history.forward()"><img src="images/for01.jpg" border="0"></a>


Where in the hell did you find window.back or window.forward?  How long have you been programming? :-)

Martin is correct, but this will work also, dude:

<A HREF="javascript:history.go(-1)"><img src="images/back01.jpg" border="0"></A>
<A HREF="javascript:history.go(+1)"><img src="images/for01.jpg" border="0"></A>

You can change the numbers to skip back or forward more spaces in history.

Hope this helps you dude,


The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

adamssrAuthor Commented:
You answered my question first and the 50 points are yours.  But my problem is not solved (my fault). When I inserted your code, it worked, but the onMouseOver and onMouseOut functions I was calling quit working. (I want the button to change onMouseOver).  Here is what I have now:

<a HREF="javascript:history.back()">
<ONMOUSEOVER="act('back');window.status='Back';return true">
<ONMOUSEOUT="inact('back');window.status=' ';return true">
<img src="images/back01.jpg" NAME="back" width="80" height="23" alt="Back" border="0"></a>

What do you suggest?  If you can help me with this, I'll throw in another 50 points.  Thanks..
adamssrAuthor Commented:
Thanks, Martin.  I figured it out myself, but you earned the points.

P.S.  A note to Shane:  
The place in hell I found window.forward() was as follows:
<FORM NAME="input">
<INPUT TYPE="button" VALUE="Back" onClick="window.forward()">
onMouseover and onMouseout are not tags.  I suppose you found these in hell, too?

How about this:

<A HREF="javascript:history.go(-1)" onMouseOver="window.status='Back'; return true;"
   onMouseOut="window.status=''"><img src="images/back01.jpg" border="0"></A>
<A HREF="javascript:history.go(+1)" onMouseOver="window.status='Forward'; return true;"
   onMouseOut="window.status=''"><img src="images/for01.jpg" border="0"></A>

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.