Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap

Q1181 How can I check if the there are more entries in the history before the current page?

You are here: irt.org | FAQ | JavaScript | History | Q1181 [ previous next ]

<script language="JavaScript"><!--

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) {

    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);

©2018 Martin Webb