PDA

View Full Version : back and forward button



jackavin
10-22-2007, 04:37 PM
How can i make Back and forward button with the image that can detect history if no history will disable the button some thing like browers

thank

magicgavin
10-22-2007, 07:08 PM
Your options are kinda limited.

history.back() or history.go(-1)
history.foward() or history.go(1)
history.length


history.length seems like a ray of hope... but its not.
if you start at page1.htm navigate to page2.htm then back to page1.htm it will only show 2 items in the history list. There is also no history index to reference to see where you are in the list. history[0] will not say page1.htm it will throw an error.

jackavin
10-22-2007, 09:40 PM
i need something like the browers do
example if no history it will disable the button

djr33
10-22-2007, 09:51 PM
if (history.length !> 1)

magicgavin
10-24-2007, 03:46 PM
With that the button will never disable once you have been to 2 webpages.
Even if you go back to the first page it will still say there are 2 items in the history.

djr33
10-24-2007, 07:09 PM
Well, that was the simplest answer.

You should/could combine this with a check to find which history item the current page matches.... anyway.... seems a bit awkward.

Here's my LOGIC, as psuedo-code:
if (current != history.veryfirst) { //ok; }
//check for the first history item, and gray out the back button if it's equal to this.
if (current != history.verylast) { //ok; }
//check for the last page, to be sure the forward button can be valid; if not, gray it out.
if (history.length>0) { //ok; }
//be sure that the length is at least two items, then you know you have one valid option, at least.
//If not, gray out BOTH buttons (if it's 1 or more, you can let the code above handle making it gray for 1 or 2 matches)

jscheuer1
10-24-2007, 08:54 PM
But, the history object is not accessible in that manner (for security reasons). The browser has a back and forward button, use them. Save your coding expertise for something that the browser doesn't have.