• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 444
  • Last Modified:

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
0
cyberystic
Asked:
cyberystic
1 Solution
 
J-MikCommented:
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!
0
 
cyberysticAuthor Commented:
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...
0
 
thirdCommented:
i don't think you can determine if you can go forward or backward. all we know is the length of the history.
0
 
J-MikCommented:
Cyberystic,

Unfortunately, I was doing my testing in Opera, which is why this worked for me. It seems that Opera will only return the length of items in the back direction, whereas Internet Explorer and Firefox count both the back and forward entries.

Anyways, the history object only has the following properties and methods:

current - The current document URL.
length - The number of entries in the history object.
next - The URL of the next document in the history object.
previous - The URL of the last document in the history object.

So it doesn't sound like what you want is possible. Sorry!

Info: http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects/obj_history.asp
0
 
GwynforWebCommented:
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.

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now