• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 10. Using the navigator, locatio... > Using the go, forward, and back Meth...

Using the go, forward, and back Methods

It’s easy to put the methods of the history object to work. In fact, we’ve already seen how to do that in Chapter 4. In that example (Listing 04-05.html on the web site), I used the back, forward, and go methods to navigate forward and backward in the browser’s history. Here’s what the code looks like:

<HTML> 
    <HEAD> 
        <TITLE>Using the history object</TITLE> 
    <SCRIPT LANGUAGE="JavaScript"> 
        <!--
        function back()
					{
					window.history.back()
					}
					function forward()
					{
					window.history.forward()
					}
					function back2()
					{
					window.history.go(-2)
					}
					function forward2()
					{
					window.history.go(2)
					} 
         // --> 
    </SCRIPT> 
    </HEAD> 

    <BODY> 
        <H1>Using the history object</H1> 
        <FORM> 
            <BR> 
            Click a button to go forward or back one page: 
            <BR> 
            <INPUT TYPE = BUTTON VALUE = "< Go back" ONCLICK = "back()">
					<INPUT TYPE = BUTTON VALUE = "Go forward >" ONCLICK = "forward()"> 
            <BR> 
            <BR> 
            Click a button to go forward or back two pages: 
            <BR> 
            <INPUT TYPE = BUTTON VALUE = "<< Go back 2" ONCLICK = "back2()">
					<INPUT TYPE = BUTTON VALUE = "Go forward 2 >>" ONCLICK = "forward2()"> 
        </FORM> 
    </BODY> 
</HTML> 

					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint