Chapter 28. Location and History Objects

IN THIS CHAPTER

  • Loading new pages and other media types via the location object

  • Security restrictions across frames

  • Navigating through the browser history under script control

Not all objects in the document object model (DOM) are things you can see in the content area of the browser window. Each browser window or frame maintains a bunch of other information about the page you are currently visiting and where you have been. The URL of the page you see in the window is called the location, and browsers store this information in the location object. As you surf the Web, the browser stores the URLs of your past pages in the history object. You can manually view what that object contains by looking in the browser menu for the item that enables you to jump back to a previously visited page. This chapter is all about these two nearly invisible, but important, objects.

These objects are not only valuable to your browser, but also valuable to snoopers who might want to write scripts to see what URLs you're viewing in another frame, or the URLs of other sites you've visited in the past dozen mouse clicks. As a result, security restrictions built into browsers limit access to some of these objects' properties (unless you use signed scripts in NN4+/Moz). For older browsers, these properties simply are not available from a script.

location Object

Properties

Methods

Event Handlers

hash

assign()

None

host

reload()

 

hostname

replace()

 

href

  

pathname

  

port

  

protocol

  

Get JavaScript® Bible, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.