Where Have You Been?

The History object, in the eyes of the JavaScript interpreter, is an array of URLs. It's an array, complete with an index beginning at 0, containing the URLs of the sites the surfer has visited since starting the browser. The History object comes in handy when you want to create navigation buttons to assist visitors to your site. In fact, that's what you'll do here. If you want to do anything with the array of URLs that is the History object, especially with a loop, you need to know how many entries are in the list. The history.length property tells you.

Checking the Length of the History List

Where have you you been?

The line document.write("

You've been to " + history.length + " different sites during this session.") refers to the history.length property of the history object. That's the number of URLs in the History list. For security reasons, a JavaScript function can't read the URLs that are stored in the History object. You can't figure out what sites your visitors have been to this way. You can, however, send them forward and back in their history lists. That's what we'll cover next time.

Insider: How the basic tech behind the Internet works
Join the discussion
Be the first to comment on this article. Our Commenting Policies