Link to home
Start Free TrialLog in
Avatar of cyberystic
cyberystic

asked on

Hide or Show <Input type="image" src="next || back.gif"> javascript wanted

Hi,

I've been trying to find a good example of hiding the <Input type="image" src="back.gif" title="Go back to previous page..."> in a table cell using CSS visibility and some sort of checking on the browser's window.history.length property, but I've had no luck.  At this point I give up, so 500 points to the first person to successfully writes a short simple javascript that uses history.back() and history.forward() and checks if they exist before the button is written out. In other words, if there is no forward page to jump to, the forward button should not appear at all (same applies for the back page/back button). I'd like to use the <input type="image" src="back.gif"> model if possible, design preference.

Thanks, and looking forward to a speedy reply as I'm stuck. :(

Cyberystic
Avatar of J-Mik
J-Mik

Cyberystic,

  While I don't think it's possible to check whether there are any forward entries, you have a few options for the back button:

You can either create your button normally and then hide it if there are no back entries:

<INPUT ID="Back" TYPE="image" SRC="back.gif" onClick="window.history.back;">

<SCRIPT TYPE="text/javascript">
<!--

   if (window.history.length == 0) document.getElementById('Back').style.visibility = 'hidden';

//-->
</SCRIPT>

Or you can simply only write the button if entries exist:

<SCRIPT TYPE="text/javascript">
<!--

   if (window.history.length > 0) document.write('<INPUT ID="Back" TYPE="image" SRC="back.gif" onClick="window.history.back;">');

//-->
</SCRIPT>

Let me know if these don't work for you!
Avatar of cyberystic

ASKER

Hi,

No Luck, Because when I tried your second example, if window.history.length > 0, I get a true result if there is a forward page or a back page.  I really want to check both forward and back and mirror the buttons in the browser exactly.  So I think I need an array that shows the position of the current window in relation to the stack and what's ahead and behind, returning a either prev, next, or both, either, or none.  Can you or someone please help solve this problem?

Thanks in advance...
i don't think you can determine if you can go forward or backward. all we know is the length of the history.
ASKER CERTIFIED SOLUTION
Avatar of J-Mik
J-Mik

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
this is not going to happen cross browser with any effectiveness. If it is for site navigation either put a flag in the first and last pages or put the names of the first and last in a .js that is included in all site pages. document.referrrer will give you the last page if the page is reached from a link in another page but the problem of forward is going to happen.