JavaScript Window History, javascripthistory
The window. history object contains the browser history.
Window History
Window. historyObjects can be written without the window prefix.
To protect user privacy, the methods for accessing this object by JavaScript are limited.
Some methods:
- History. back ()-same as clicking the back button in the browser
- History. forward ()-same as clicking the button in the browser to forward
Window History Back
The history. back () method loads the previous URL in the history list.
This is the same as clicking the back button in the browser:
Instance
After the button is created on the page:
<Html>
<Head>
<Script>
Function goBack ()
{
Window. history. back ()
}
</Script>
</Head>
<Body>
<Input type = "button" value = "Back" onclick = "goBack ()">
</Body>
</Html>
The above code is output:
Window History Forward
The history forward () method loads the next URL in the history list.
This is the same as clicking the forward button in the browser:
Instance
Create a forward button on the page:
<Html>
<Head>
<Script>
Function goForward ()
{
Window. history. forward ()
}
</Script>
</Head>
<Body>
<Input type = "button" value = "Forward" onclick = "goForward ()">
</Body>
</Html>
The above code is output: