Questions And Answers

More Tutorials

Javascript History


history.pushState(state object, title, url)

This method allows to ADD histories entries. For more reference, Please have a look on this document : pushState() method

window.history.pushState("", "Sample Title", "/example/path.html");

This example inserts a new record into the history, address bar, and page title.
Note this is different from the history.replaceState(). Which updates the current history entry, rather than
adding a new one.


history.replaceState(data, title [, url ])

This method modifies the current history entry instead of creating a new one. Mainly used when we want to update URL of the current history entry.

window.history.replaceState("", "Sample Title", "/example/path.html");

This example replaces the current history, address bar, and page title.
Note this is different from the history.pushState(). Which inserts a new history entry, rather than replacing the
current one.

Load a specific URL from the history list

go() method

The go() method loads a specific URL from the history list. The parameter can either be a number which goes to the URL within the specific position (-1 goes back one page, 1 goes forward one page), or a string. The string must be a partial or full URL, and the function will go to the first URL that matches the string.



Click on the button to go back two pages:

 <script type="text/javascript">
 function goBack()
 <input type="button" value="Go back 2 pages" onclick="goBack()" />


In this page (written and validated by ) you learned about Javascript History . What's Next? If you are interested in completing Javascript tutorial, your next topic will be learning about: Javascript Screen.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.