Tracking User Navigation


Tracking User Navigation

You can use the document object's referrer property to determine the URL of the page in which the user clicked a link to navigate to the current page. (This property holds a non-empty value only when the user reaches the current page through a link from the previous page.) Here's an examplewhen you open Listing 09-05.html, you'll see a link to the next page, Listing 09-06.html; clicking that link takes you to the next page, where the URL you came from is displayed:

(Listing 09-05.html on the web site)
 <HTML>      <HEAD>          <TITLE>Here's a Web Page</TITLE>      </HEAD>      <BODY>          <H1>Here's a Web Page</H1>          <A HREF="09-06.html">Go to the next Web page!</A>      </BODY>  </HTML> 
(Listing 09-06.html on the web site)
 <HTML>      <HEAD>          <TITLE>Tracking User Navigation</TITLE>      </HEAD>      <BODY>          <H1>Tracking User Navigation</H1>          <SCRIPT LANGUAGE="JavaScript">              <!--                 document.write("You came from:" + document.referrer)              // -->          </SCRIPT>      </BODY>  </HTML> 

Tip

This property works only when the pages involved have been served from a web server, not on your local hard disk.




Inside Javascript
Inside JavaScript
ISBN: 0735712859
EAN: 2147483647
Year: 2005
Pages: 492
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net