WEBINAR: On-demand webcast
How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >
Browser History List
history object, so you can't use the list to figure out where your visitors have been.
The history object has only one property:
length. It returns the number of URL's in the history list. It's not particularly useful. You could use it as in the script below, (although it doesn't do anything except tell your visitor what they already know):
document.write("You\'ve been to "+ history.length +" site(s) in this browser session."); // combine the two lines above
forward() methods do exactly what they say. They reload the previous page or go to the next page in the browser's history. They act exactly like the browser's Back and Forward buttons. The methods can be written as follows:
<form> <input type="Button" name="back" value="Go Back" onClick="history.back()"> // combine with line above <input type="Button" name="forward" value="Go Forward" onClick="history.forward()"> // combine with line above </form>
[Ctrl]and the link. This opens the link in a new tab. Doing it that way, I wouldn't have any previous URL listing in the history of that new tab. Or, if I use IE and press
[Shift]and the link, it will open in a new window. Once again, there would be no previous URL listed in the history file. Even though your visitor may use navigation techniques like the ones I just outlined, they probably won't understand the whole history thing. If there is a link to go back, and they have no URL in their history, it could prove to be a bit frustrating. And when people become technologically frustrated, they often say: "I'm outta here!"
go() method is used to move forward or back more than one page at a time in the history list. This is done by placing the number of pages you want to go in the parentheses. Positive numbers move the browser forward; negative numbers move the browser backward. It's like moving in steps. If you want to go forward one page (one step), use this:
To go back two pages (two steps), you would use this:
The problem with this method is that you need to make sure that the browser's history contains that many URLs.
This method can also be used to perform a soft reload of the current page. This is useful when a user has entered data into a form and you don't want to erase it. This is accomplished by using the script below. Be aware, however, that IE may reload a fresh version of the page.