O'Reilly logo

JavaScript® Bible, Sixth Edition by Danny Goodman, Brendan Eich, Michael Morrison

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 17. 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 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 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

  

search

  

Syntax

Loading ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required