Javascript - checking forward history?

  Charence 01:41 02 Mar 2007


I'm trying to write an if statement in javascript to check if the forward entry exists in the history. I'm doing this because on the website I have created, I want to disable the forward button and also back button when a forward/back entry does not exist. How can I do this?

I tried:
if (!history.forward()) {
//no forward entry
else {
//forward entry exists

which works for the case where no forward entry exists in history, however, when there is a forward entry, it will just execute forward(), which I don't want, I just want to check. Are there any methods I could use for history apart from length, back, forward and go?

If there is another way which this can be done, please let me know.

Thanks in advance!


  PurplePenny 08:53 02 Mar 2007

Why would you want to disable the forward and back buttons? If their is no forward history the forward button won't work anyway.

  Charence 09:38 02 Mar 2007

Yes, but I also want to make the buttons appear disabled so that the user doesn't attempt to press it and it is clear to them that the button won't do anything.

What if I store the history length when the page first loads, then I have a counter which increments when I go to another page and decrements when I press back. If I then do a comparison of history.length with the counter, I should be able to work out if I'm at the end/start of my history right? Is this psosible in Javascript? Or what other language should I use?

I know that the above idea ^^^ wouldn't let me press back if I was at the position where I stored the history length when the website is first accessed, this doesn't matter.

Also, you can assume that when this website is viewed, none of the toolbars will be visible.



  Charence 15:23 02 Mar 2007

Hi, the buttons are going to be on the page.

I'm not sure about IE7, but even if the back/forward on toolbar is visible, it doesn't matter. I said that they can be assumed not to be visible earlier because I didn't want anyone to suggest using the buttons on the toolbar.



  PurplePenny 20:25 02 Mar 2007

"Also, you can assume that when this website is viewed, none of the toolbars will be visible."

Which toolbars will not be visible?

  Charence 23:18 02 Mar 2007

never mind, doesn't matter anymore...

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

OnePlus 5 review

Alice Saey's mesmerising animation for Dutch singer Mark Lotterman

iPad Pro 10.5in (2017) review

Comment booster votre iPhone ?