history.go(url/number)
In this chapter you will learn:
Go to a step
The go()
method can navigate through the
user's history backward or forward.
go()
accepts an integer representing the
number of pages to go backward or forward a its single argument.
A negative number moves backward in history and a positive number moves forward.
//go back one page /*from j a va 2s .c om*/
history.go(-1);
//go forward one page
history.go(1);
//go forward two pages
history.go(2);
<!DOCTYPE HTML> <!--from j a v a 2s .co m-->
<html>
<body>
<script>
history.go(-1);
</script>
</body>
</html>
Pass in string parameter
The go()
method argument can be a string.
The browser navigates to the first location in
history that contains the given string.
The closest location may be either backward or forward. If there's no entry in history matching the string, then the method does nothing:
<!DOCTYPE HTML> <!--from j a v a 2 s. c o m-->
<html>
<body>
<script type="text/javascript">
window.history.go("http://www.java2s.com");
</script>
</body>
</html>
Next chapter...
What you will learn in the next chapter:
Home » Javascript Tutorial » History