|
targetThe target property initially reflects the TARGET property of the <A HREF="…"> or <AREA HREF="…"> HTML definitions. Setting the value of this property overrides the initial definition. The target property (document.links[index].target) cannot be assigned a JavaScript expression or variable. Referring DocumentsWhen a user clicks a link in one document and causes a new page to load in the same or other window, the calling document is known as the referring document. When a user arrives at a page via a link from another page (and not from his or her bookmark, history list, friends, etc.), the URL of the referring page is reflected in the new page as a read-only property, document.referrer. You should also know that a referring document is also called the source document, whereas the new page the referrer document links to is known as the destination document. The property document.referred is very useful for tracking a user’s movement inside a large site you maintain by yourself. It is not helpful at all if the user surfs to foreign pages, so, unless Playboy provides a link to your page, you won’t be able to greet the user with a message such as “Naughty boy—Playboy is for grown-ups only!” Suppose you have a page on your site, C.html, that is linked from two different pages, A.html and B.html. Let’s say A.html includes important copyright information on a shareware product available on C.html, and B.html provides important instructions on installing the software package. You can use the following JavaScript script on C.html to check where the user came from and to print a link to the third page:
<SCRIPT LANGUAGE="JavaScript"> <!-- begin JavaScript *immediate* script // assign greater than character without literally displaying it var gt = unescape("%3E") if (document.referred.indexOf("A.html") == –1) document.write('<A HREF="A.html"'+gt+'Copyright notice</A'+gt) if (document.referred.indexOf("B.html") == –1) document.write('<A HREF="B.html"' + gt + 'Installation instructions</A' + gt) // --> </SCRIPT>
This script prints links to the documents the user has not come from. It prints A.html it the user has not come from A.html, B.html if the user has not come from B.html, or both links if the user has apparently arrived from a different document or not from a link at all. SummaryIn this chapter, we discussed the Link, Area, and Anchor objects. You learned that the only way to reference one of these objects is by either document.links or document.anchors. There are three important concepts you should remember from this chapter:
|
|||||||||||||||||||||||
With any suggestions or questions please feel free to contact us |