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
cyberysticAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

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.