Client-side object | |
Implemented in |
Navigator 2.0 Navigator 3.0: added current, next, and previous properties;
|
History
objects are predefined JavaScript objects that you access through the history
property of a Window
object.Location.replace
method. This replaces the current page with a new one without generating a history entry. See Location.replace
.
You can refer to the history
entries by using the Window.history
array. This array contains an entry for each history entry in source order. Each array entry is a string containing a URL. For example, if the history list contains three named entries, these entries are reflected as history[0]
, history[1]
, and history[2]
.
| Loads the previous URL in the history list. |
| Loads the next URL in the history list. |
| Loads a URL from the history list. |
history.go(-3)Example 2. You can use the
history
object with a specific window or frame. The following example causes window2
to go back one item in its window (or session) history:window2.history.back()Example 3. The following example causes the second frame in a frameset to go back one item:
parent.frames[1].history.back()Example 4. The following example causes the frame named
frame1
in a frameset to go back one item:parent.frame1.history.back()Example 5. The following example causes the frame named
frame2
in window2
to go back one item:window2.frame2.history.back()Example 6. The following code determines whether the first entry in the
history
array contains the string "NETSCAPE"
. If it does, the function myFunction
is called.if (history[0].indexOf("NETSCAPE") != -1) {Example 7. The following example displays the entire history list:
myFunction(history[0])
}
document.writeln("<B>history is</B> " + history)This code displays output similar to the following:
history is
Welcome to Netscape http://home.netscape.com/
Sun Microsystems http://www.sun.com/
Royal Airways http://www.supernet.net/~dugbrown/
Location
, Location.replace
Property of |
History
|
Read-only | |
Implemented in | Navigator 3.0 |
Navigator 4.0: Getting the value of this property requires the UniversalBrowserRead
privilege. It has no value if you do not have this privilege. For information on security in Navigator 4.0, see Chapter 7, "JavaScript Security," in the JavaScript Guide.
history.current
contains the string "netscape.com"
. If it does, the function myFunction
is called.if (history.current.indexOf("netscape.com") != -1) {
myFunction(history.current)
}
History.next
, History.previous
history
array.
Property of |
History
|
Read-only | |
Implemented in | Navigator 2.0 |
UniversalBrowserRead
privilege. For information on security in Navigator 4.0, see Chapter 7, "JavaScript Security," in the JavaScript Guide.
Property of |
History
|
Read-only | |
Implemented in | Navigator 3.0 |
Navigator 4.0: Getting the value of this property requires the UniversalBrowserRead
privilege. It has no value if you do not have this privilege. For information on security in Navigator 4.0, see Chapter 7, "JavaScript Security," in the JavaScript Guide.
next
property reflects the URL that would be used if the user chose Forward from the Go menu. history.next
contains the string "NETSCAPE.COM"
. If it does, the function myFunction
is called.if (history.next.indexOf("NETSCAPE.COM") != -1) {
myFunction(history.next)
}
History.current
, History.previous
Property of |
History
|
Read-only | |
Implemented in | Navigator 3.0 |
Navigator 4.0: Getting the value of this property requires the UniversalBrowserRead
privilege. It has no value if you do not have this privilege. For information on security in Navigator 4.0, see Chapter 7, "JavaScript Security," in the JavaScript Guide.
previous
property reflects the URL that would be used if the user chose Back from the Go menu. history.previous
contains the string "NETSCAPE.COM"
. If it does, the function myFunction
is called.if (history.previous.indexOf("NETSCAPE.COM") != -1) {
myFunction(history.previous)
}
History.current
, History.next
Method of |
History
|
Implemented in | Navigator 2.0 |
back()
back
method is the same as history.go(-1)
.<P><INPUT TYPE="button" VALUE="< Go Back"
onClick="history.back()">
<P><INPUT TYPE="button" VALUE="> Go Back"
onClick="myWindow.back()">
History.forward
, History.go
Method of |
History
|
Implemented in | Navigator 2.0 |
forward()
forward
method is the same as history.go(1)
.<P><INPUT TYPE="button" VALUE="< Forward"
onClick="history.forward()">
<P><INPUT TYPE="button" VALUE="> Forward"
onClick="myWindow.forward()">
History.back
, History.go
Method of |
History
|
Implemented in | Navigator 2.0 |
go(delta)
go(location)
delta | An integer representing a relative position in the history list. |
location | A string representing all or part of a URL in the history list. |
go
method navigates to the location in the history list determined by the specified parameter.
If the delta
argument is 0, the browser reloads the current page. If it is an integer greater than 0, the go
method loads the URL that is that number of entries forward in the history list; otherwise, it loads the URL that is that number of entries backward in the history list.
The location
argument is a string. Use location
to load the nearest history entry whose URL contains location
as a substring. Matching the URL to the location
parameter is case-insensitive. Each section of a URL contains different information. See Location
for a description of the URL components.
The go
method creates a new entry in the history list. To load a URL without creating an entry in the history list, use Location.replace
.
"home.netscape.com"
:<P><INPUT TYPE="button" VALUE="Go"The following button navigates to the URL that is three entries backward in the history list:
onClick="history.go('home.netscape.com')">
<P><INPUT TYPE="button" VALUE="Go"
onClick="history.go(-3)">
History.back
, History.forward
, Location.reload
, Location.replace
Last Updated: 10/31/97 12:31:44