JavaScript » Objects » History

The History object is a predefined JavaScript object which is accessible through the history property of a window object.

The window.history property is an array of URL strings which reflect the entries in the History object. The History object consists of an array of URLs, accessible through the browser's Go menu, which the client has visited within a window. It is possible to change a window's current URL without an entry being made in the History object by using the location.replace method.

Properties

constructor

Syntax: Object.constructor

This specifies a function to create an object's property and is inherited by all objects from their prototype.

current

Syntax: history.current

The current property contains the complete URL of the current History entry.

length

Syntax: history.length

The length property contains the number of elements in the History list.

next

Syntax: history.next

The next property contains the complete URL of the next element in the History list, and is the equivalent of the URL the user would go to if they selected Forward in the Go menu.

previous

Syntax: history.previous

The previous property contains the complete URL of the previous element in the History list, and is the equivalent of the URL the user would go to if they selected Back in the Go menu.

prototype

Syntax: Object.prototype.name = value

This allows the addition of properties and methods to any object.

Methods

back

Syntax: history.back()

The back method loads the previous URL in the History list, and is equivalent to the browser's Back button and to history.go(-1).

eval

Syntax: Object.eval(string)

The eval method is deprecated as a method of Object, but is still used as a high level function. It evaluates a string of JavaScript in the context of an object.

forward

Syntax: history.forward()

The forward method loads the next URL in the History list, and is equivalent to the browser's Forward button and to history.go(1).

go

Syntax: history.go(delta)
history.go(location)

The go method loads a specified URL from the History list.

toSource

Syntax: Object.toSource()

The toSource method returns a literal representing the source code of an object. This can then be used to create a new object.

toString

Syntax: Object.toString()

The toString method returns a string representing a specified object.

unwatch

Syntax: Object.unwatch(property)

This method removes a watchpoint set for an object and property name with the watch method.

valueOf

Syntax: Object.valueOf()

This method returns a primitive value for a specified object.

watch

Syntax: Object.watch(property, handlerfunction)

This method adds a watchpoint to a property of the object.

See Also: