JavaScript Example 2-3
Fun with the History List

Click Here for Previous JavaScript Tutorial Home Click Here for Next

This example is an effort to examine and manipulate the history list of a window. Unfortunately, it is still a work in progress -- it is incomplete. For now, I suggest you skip to the next example.

A popup window should appear as soon as this page loads.

You can make it load the next Example file by clicking here.

You can make it reload itself by clicking here.

The history object

One is supposed to be able to print the entire history list of the current window using the following:

   document.writeln("history is " + history)
but I can't get it to work right.
Show My History:

Show Remote History:

history.length

Returns the number of elements in the history array. In this case we're reading the history list of the remote window.

Show My history.length:

Show Remote history.length:

The following would read the history list of the current window. It works OK with IE, but so far not with Netscape.

   document.writeln("history list contains " + 
                    history.length + " elements.")

In reading the history of the remote window, I found that I get an access error when its current URL is my home page (which is on a remote system), but it works OK when the current URL is the little example file (on the current machine) that I originally open. I think this is because of the "Same Origin Policy" in the Netscape 4 JavaScript security model. See http://developer.netscape.com/docs/manuals/communicator/jsguide4/index.htm?content=sec.htm

Further investigation reveals that this is indeed pretty much the problem. In NS4+ it is supposedly possible to work around this by setting the privilege:

 netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");

However I still can't get it to work. Since it isn't going to help me do what I want, I'll abandon the effort...

Resources

Netscape's JavaScript Reference Manual
Refer to the section dealing with the history object.
 
Click Here for Previous JavaScript Tutorial Home Click Here for Next