You are here: irt.org | FAQ | JavaScript | History | Q1181 [ previous next ]
<script language="JavaScript"><!-- alert(history.length); //--></script>
But this only gives you the length - if the user has gone back in their browser, or has picked an entry from thier browser history - you'll not know the history number of the current page.
In Netscape Navigator 4 you can attempt to request extra priviledges and check to see what URLs are in the history object:
<script language="JavaScript"><!--
if (document.layers) {
netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');
var found=false,first=count=-1;
if (history[history.length-1] == window.location.href)
first = history.length-1,found = true,count = 1;
if (history.length>1) {
for (var i=history.length-1; i>-1; i--) {
if (history[i] == window.location.href) {
if (!found) first = i,found = true,count = 1; else count++;
}
}
}
alert('actual entries=' + history.length + ' first position=' + first + ' matches found=' + count);
}
//--></script>