HTML and CSS Reference
In-Depth Information
10.1.6 The history Object
The history object is a property of the window object. It keeps track of the pages (in a
stack) that the user has visited. The history object is most commonly used in JavaScript
to move back or forward on a page, similar to the back button and forward button sup-
ported by your browser. The history object can reference only those pages that have been
visited; that is, those pages on its stack. It has a length property and three methods called
go() , back() , and forward() . See Tables 10.15 and 10.16.
Table 10.15 Properties of the history Object
Property
What It Describes in the URL
current
The current document URL.
length
The number of entries in the history object.
next
The URL of the next document in the
history object.
previous
The URL of the previous document in the
history object.
search
The query string.
Table 10.16 Methods of the history Object
Method
What It Does
back()
Goes to the previous URL entry in the history list; like the browser's back
button.
forward()
Goes to the next URL entry in the history list; like the browser's forward
button.
go()
The browser will go forward or back (if the value is negative) the
number of specified pages in the history object.
EXAMPLE
history.go(-3)
// Go back three pages
history.go(2)
// Go forward three pages
back()
// Same as history.go(-1)
forward()
// Same as history.go(1)
 
 
Search WWH ::




Custom Search