JavaScript Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Java-Script Tutorial
Introduction Introduction
Variables Variables
Operators Operators
Statements Statements
Loops Loops
Functions Functions
Objects Objects
Arrays Arrays
Cookies JS Cookies
Browser Objects Browser Objects
Form DOM Form DOM
Style Objects DOM Style Objects
Forums Ask Your Doubts
Scraps More about Javascript
Feedback Feedback
 




History Go Method


Tutorials Javascript

Topic

How to move to a certain page in history list using javascript



Explanation

Methods or Function: go()
        go() function takes one argument. It can take an integer argument or a string argument.

Code: go(n);
where n can be a negative, zero or positive integer.
a) if n<0, it takes to the previous pages in the history list. i.e go(-1) takes to previous page, go(-2) takes two page back and so on..

b) if n=0, nothing happens

c) if n>0, it takes to the next pages in the history list. i.e go(1) takes to next back, go(2) takes two pages ahead and so on..

Example: To create a button that loads two pages backward using javascript.
Code:
<script language="javascript">
function gourl(){
history.go(-2);
}
</script>
<input type=button value="go back" onClick=gourl()>

Result:
In the above example
a) we created a button
b) added a onClick event listener to the button.
c) when user clicks on the button the javascript function gourl()
will be invoked.
d) in the function we call history.go(-2) to go two steps backward.





A Note
Javascript (JS) is one of the most used languages in the world. Some times spelled as Java Script. Hope you enjoy this tutorial. Do send your feedback or suggestions on this javascript or java script tutorial. This is a copyright content.

Other Links

web hosting