|
Javascript "Go Back" in Browser History Script
JavaScript includes what is called a history object. It tracks the URLs visited by the browser. You can use this browser history as a means to return to the previous page (or, for that matter, to go back and forward through the history). This is especially useful when a hard-coded, specific link is not possible; for instance, in cases where you do not necessarily know the address of the previously visited page. This is how a "previous page" or "go-back" link would appear in your HTML code:
Here is the actual link: Go Back
Alternatively, if you wanted to go forward instead of backward in the history, you would write the code thus:
Here is the actual link: Go Forward
The numbers in the parentheses are the number of pages to move (forward or back, respectively, in the above examples). You can also move more than one page; for instance javascript.history.go(-3) would navigate three pages back in the history. Note that if there is no page in the history to go to, the JavaScript does not error out; it simply does nothing.
Here is the code if you use a button:
Here is the actual link:
Here is the code if you use an image:
Here is the actual link: |
|
|