| HistoryContains an array of information on the URLs that the client has visited within a window. This information is stored in a history list and is accessible through the browser's Go menu.
Client-side object | | Implemented in | Navigator 2.0 Navigator 3.0: added current, next, and previous properties; |
Created byHistory objects are predefined JavaScript objects that you access through the history property of a Window object. DescriptionTo change a window's current URL without generating a history entry, you can use the 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] .If you access the history array without specifying an array element, the browser returns a string of HTML which displays a table of URLs, each of which is a link. Property Summary
current
| Specifies the URL of the current history entry. | length
| Reflects the number of entries in the history list. | next
| Specifies the URL of the next history entry. | previous
| Specifies the URL of the previous history entry. |
Method Summary
back
| Loads the previous URL in the history list. | forward
| Loads the next URL in the history list. | go
| Loads a URL from the history list. |
ExamplesExample 1. The following example goes to the URL the user visited three clicks ago in the current window.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) { myFunction(history[0]) } Example 7. The following example displays the entire history list: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/ See alsoLocation , Location.replace PropertiescurrentA string specifying the complete URL of the current history entry.
Property of | History | Read-only | | Implemented in | Navigator 3.0 |
SecurityNavigator 3.0: This property is tainted by default. It has no value of data tainting is disabled. For information on data tainting, see "JavaScript Security".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. ExamplesThe following example determines whether 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) } See alsoHistory.next , History.previous lengthThe number of elements in the history array.
Property of | History | Read-only | | Implemented in | Navigator 2.0 |
SecurityNavigator 4.0: Getting the value of this property requires the UniversalBrowserRead privilege. For information on security in Navigator 4.0, see Chapter 7, "JavaScript Security," in the JavaScript Guide. nextA string specifying the complete URL of the next history entry.
Property of | History | Read-only | | Implemented in | Navigator 3.0 |
SecurityNavigator 3.0: This property is tainted by default. It has no value of data tainting is disabled. For information on data tainting, see "JavaScript Security".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. DescriptionThe next property reflects the URL that would be used if the user chose Forward from the Go menu. ExamplesThe following example determines whether 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) } See alsoHistory.current , History.previous previousA string specifying the complete URL of the previous history entry.
Property of | History | Read-only | | Implemented in | Navigator 3.0 |
SecurityNavigator 3.0: This property is tainted by default. It has no value of data tainting is disabled. For information on data tainting, see "JavaScript Security".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. DescriptionThe previous property reflects the URL that would be used if the user chose Back from the Go menu. ExamplesThe following example determines whether 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) } See alsoHistory.current , History.next MethodsbackLoads the previous URL in the history list.
Method of | History | Implemented in | Navigator 2.0 |
Syntaxback() ParametersNone DescriptionThis method performs the same action as a user choosing the Back button in the browser. The back method is the same as history.go(-1) . ExamplesThe following custom buttons perform the same operation as the browser's Back button:<P><INPUT TYPE="button" VALUE="< Go Back" onClick="history.back()"> <P><INPUT TYPE="button" VALUE="> Go Back" onClick="myWindow.back()"> See alsoHistory.forward , History.go forwardLoads the next URL in the history list.
Method of | History | Implemented in | Navigator 2.0 |
Syntaxforward() ParametersNone DescriptionThis method performs the same action as a user choosing the Forward button in the browser. The forward method is the same as history.go(1) . ExamplesThe following custom buttons perform the same operation as the browser's Forward button:<P><INPUT TYPE="button" VALUE="< Forward" onClick="history.forward()"> <P><INPUT TYPE="button" VALUE="> Forward" onClick="myWindow.forward()"> See alsoHistory.back , History.go goLoads a URL from the history list.
Method of | History | Implemented in | Navigator 2.0 |
Syntaxgo(delta) go(location) Parameters
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. |
DescriptionThe 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 . ExamplesThe following button navigates to the nearest history entry that contains the string "home.netscape.com" :<P><INPUT TYPE="button" VALUE="Go" onClick="history.go('home.netscape.com')"> The following button navigates to the URL that is three entries backward in the history list:<P><INPUT TYPE="button" VALUE="Go" onClick="history.go(-3)"> See alsoHistory.back , History.forward , Location.reload , Location.replace
screenContains properties describing the display screen and colors.
Client-side object | | Implemented in | Navigator 4.0 |
Created byThe JavaScript runtime engine creates the screen object for you. You can access its properties automatically. DescriptionThis object contains read-only properties that allow you to get information about the user's display. Property Summary
availHeight
| Specifies the height of the screen, in pixels, minus permanent or semipermanent user interface features displayed by the operating system, such as the Taskbar on Windows. | availWidth
| Specifies the width of the screen, in pixels, minus permanent or semipermanent user interface features displayed by the operating system, such as the Taskbar on Windows. | colorDepth
| The bit depth of the color palette, if one is in use; otherwise, the value is derived from screen.pixelDepth . | height
| Display screen height. | pixelDepth
| Display screen color resolution (bits per pixel). | width
| Display screen width. |
ExamplesThe following function creates a string containing the current display properties:function screen_properties() { document.examples.results.value = "("+screen.width+" x "+screen.height+") pixels, "+ screen.pixelDepth +" bit depth, "+ screen.colorDepth +" bit color palette depth."; } // end function screen_properties PropertiesavailHeightSpecifies the height of the screen, in pixels, minus permanent or semipermanent user interface features displayed by the operating system, such as the Taskbar on Windows.
Property of | screen | Implemented in | Navigator 4.0 |
availWidthSpecifies the width of the screen, in pixels, minus permanent or semipermanent user interface features displayed by the operating system, such as the Taskbar on Windows.
Property of | screen | Implemented in | Navigator 4.0 |
colorDepthThe bit depth of the color palette in bits per pixel, if a color palette is in use. Otherwise, this property is derived from screen.pixelDepth .
Property of | screen | Implemented in | Navigator 4.0 |
heightDisplay screen height, in pixels.
Property of | screen | Implemented in | Navigator 4.0 |
pixelDepthDisplay screen color resolution, in bits per pixel.
Property of | screen | Implemented in | Navigator 4.0 |
widthDisplay screen width, in pixels.
Property of | screen | Implemented in | Navigator 4.0 | |
| |