Window history.go() method
- Previous Page forward()
- Next Page length
- Go to the Previous Level Window History
Definition and usage
history.go()
The method loads a URL (page) from the history list.
history.go()
The method is only valid when the page exists in the history list.
Comment
history.go(0)
Reload the page.
history.go(-1)
With history.back()
Same.
history.go(1)
With history.forward()
Same.
See also:
Example
Create a button to go back two pages:
<button onclick="history.go(-2)">Go back two pages</button>
The output of the above code will be:
Click to return to see how it works.
(Only valid when there are previous pages in your history list)
Syntax
history.go(number)
Parameter
Parameter | Description |
---|---|
number | Required. Negative values go back. Positive values go forward. |
Return value
None.
Browser support
All browsers support history.go()
:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support | Support |
- Previous Page forward()
- Next Page length
- Go to the Previous Level Window History