Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q991 Can I sniff the browsers history and then redirect the browser depending on where they have been before?

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

Use the documents referrer property:

<script language="JavaScript"><!--
if (document.referrer.indexOf('page2.htm') > -1)
    location.href = 'page2.htm';
else if (document.referrer.indexOf('page3.htm') > -1)
    location.href = 'page2.htm';
else
    location.href = 'default.htm';
//--></script>

The following can only be done in Netscape Navigator 4+, but works on previous pages and not just the last:

<script language="JavaScript"><!--
if (document.layers) {
    netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');
    var nextUrl = '';
    for (var i=window.history.length-1;i>-1;i--) {
        if (window.history[i].indexOf('irt.org') > -1) {
            nextUrl = 'http://www.irt.org/script/faq.htm';
            break;
        }
        if (window.history[i].indexOf('netscape.com') > -1) {
            nextUrl = 'http://developer.netscape.com/';
            break;
        }
    }
    if (nextUrl != '')
        location.href = nextUrl;
}
//--></script>

©2018 Martin Webb