History

JavaScript History property is used to access browser history. The history stored in our browser is access using JavaScript history property of current browser session. There are three properties of javascript history.

history.length is used to check total histories in current browser session. Minimum value for history.length is 1 and can go up.


JS History Properties


History.back

history.back method is used to go back by one step only. There is no parameter in back method. The limitation of history.back method is that it can go back only one step. See example




    history.back()

History.forward

history.forward method is used to go forward by one step . There is no parameter in forward method. The limitation of history.forward method is that it can go forward only one page. See example




    history.forward()

History.go

history.go method can be used to go back and forward by single or multiple pages. The parameter in go method tell the path. It can be any number, positive, negative or 0 (zero). Zero can reload page, negative can go back and positive can go forward. See examples

History.go examples




    history.go(-1);         // goes back 1 page
    history.go(1);          // goes forward 1 page
    history.go(0);          // refresh current page

History.go for multiple pages




    history.go(-2);         // goes 2 pages back
    history.go(2);          // goes 2 pages forward