Forum Moderators: open

Message Too Old, No Replies

"Back" history.length

         

gph

11:26 pm on Jul 23, 2002 (gmt 0)

10+ Year Member



I'm trying to determine if the browser has atleast one page to go back
to in its history, then display <a href="javascript:history.go(-1);">Back</a>

The page below works in Opera 6 but includes forward history in IE6, Mozilla 1.0.

I have 2 questions:

1/ Is there a way to make this test more accurate in IE5+ and/or Mozilla 1.0?

2/ Is it possible to get your actual position in the history array?

<html>
<title></title>
<body>
<script>
onload = function() {
if ((document.layers) ¦¦ (document.getElementById && !document.all)) {
var pages = history.length-1;
} else {
var pages = history.length;
}
if (pages != 0) {
alert("history.length = "+history.length+" page(s)")
} else {
alert("null")
}
}
</script>
</body>
</html>

Thanks for your help.

Purple Martin

1:18 am on Jul 24, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I looked for an answer in the JavaScript Bible (by Danny Goodman), and decided the easiest thing was to give you a straight quote from it:

Use the history.length property to count the items in the history list. Unfortunately, this nugget of information is not particularly helpful in scripting navigation relative to the current location because your script cannot extract anything from the place in the history queue where the current document is located. If the current document is at the top of the list (the most recently loaded), you can calculate relative to that location. But users can use the Go/View menu to jump around the history as they like. The position of a listing in the history does not change by virtue of navigating back to that document. A history.length of 1, however, indicates that the current document is the first one the user loaded since starting the browser software.

HTH

tedster

2:09 am on Jul 24, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A history.length of 1, however, indicates that the current document is the first one the user loaded since starting the browser software.

Shouldn't that read "since opening that particular browser window"? I'm an Opera shift/click addict, so you wouldn't want to count on my window histories to tell you too much about my trip around your site!

rewboss

8:23 am on Jul 24, 2002 (gmt 0)

10+ Year Member



Access to the browser's History list is severely restricted for security reasons. If you want to go to all the trouble and expense of getting your scripts digitally signed, you can ask Netscape to grant you extra privileges (which the user can always deny), giving you greater access to the History list, but apart from that all you really have access to is history.length, history.go(), history.back() and history.forward(). You can't even use the history list to get the URL of the current document without UniversalBrowserRead.

gph

11:04 pm on Jul 24, 2002 (gmt 0)

10+ Year Member



Thank you all for your insight.