Modifying history - the history.go(distance) method

history.go(x) is equivalent to the user clicking his forward button x times in the browser. However, you can specify the distance to move, that is history.go(5); . This equivalent to the user hitting the forward button in the browser five times.

Similarly, you can specify negative values as well to make it move backward. Specifying 0 or no value will simply refresh the page:

history.go(5); // forwards the browser 5 timeshistory.go(-1); // similar effect of clicking back buttonhistory.go(0); // refreshes pagehistory.go(); // refreshes page

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.