The history object stores all the URLs of the HTML pages through which the user has passed during the current browser session. It is a copy of the information stored in the Go option from the Navigator menu bar.
By default, access to the object is given in the following format:
As access methods and properties are done in the same way, one should know each.
lenght – Reports the number of page views.
back – Returns to the previous page, according to the page regarding the history object. Same as clicking your browser’s back button.
Eg.: history.back ()
Forward – Moves to the next page, according to the page regarding the history object. Same as clicking the browser forward button.
Eg.: history.forward ()
Go – Allows any URL is present in the list of visited pages of the history object, is loaded.
Eg.: history.go (parameter)
There are two possibilities for “parameter” in this case:
- Parameter is a number: to set a number, this must be an integer. If it is positive, the target page is “parameter” to the front pages. Whereas if it is negative, the target page is “parameter” pages back;
- Parameter is a string: In this case, the target is the URL that most closely resembles the string value defined by “parameter”.
defaultStatus – Determines the default contents of the browser’s status bar when nothing important is happening.
Eg widow.defaultStatus = ‘Anything’
frames – Vector that stores references to the frames of the current window.
Eg parent.frames.lenght // get the number of frames of the main window, assuming that we are in a frame.
parent – Refers to the parent of the current frame window.
self – Refers to the current window.
Eg.: self.defaultStatus = ‘Anything’
status – Sets a message that will appear in the browser footer, replacing for example, the URL of a link when we’re with the mouse over the link.
Eg.: window.status = “any text”
Eg.: top.close () // close the main browser window
window – Refers to the current window. It operates analogously to self.
Eg.: window.status = ‘Anything’
alert – Displays an alert box, followed by a beep and the OK button.
Eg.: alert (‘This is an alert window!’)
close – Ends the current browser session.
Eg.: top.close ()
confirm – shows a dialog box, followed by a beep and buttons ‘OK’ and ‘Cancel’. It returns a true value if the user chooses OK.
Eg.: return = confirm (‘Do you want to proceed?’)
open – Open a new browser session, as if the user pressed N +
Eg.: window.open (“URL”, “name” [“character”])
- URL: address initially selected when opening a new window;
- Name: name of the new window, defined by the programmer;
- Features – number of configuration options for the new window. If specified, must be on the same string, separated by commas and no spaces contain:
the toolbar = 0 or 1
The location = 0 or 1
the directories = 0 or 1
status = 0 or 1 menubar = 0 or 1
The scrollbars = 0 or 1
the resizable = 0 or 1
the width = positive integer value
the height = positive integer value
prompt – Sets up a data entry box, in a simplified manner compared with the text object. Eg prompt (label [, value])
- label: text that appears next to the box;
- Value: the initial contents of the box;
- setTimeout – Makes an expression to be evaluated after a certain time (in milliseconds).
ID – identifier used for canceling setTimeOut.
clearTimeout – Cancel setTimeOut.
Eg.: clearTimeout (ID)
The window object also has two events that can be used in the handling of the window data and including:
- onLoad: It occurs as soon as the HTML page finishes loading.
- onUnload: occurs as soon as the user leaves the current page.
Visit our blog and check out more content!