Tutorials
JavaScriptLink object is also a property of the document object. The link object is used to get or capture a text or image link present in a document. Similar to the anchor object having anchor array, all the links are contained in link array.
The link object has all the properties of the location object such as; hash, host, hostname, href, pathname, port, protocol and search. Additionally, link object has one more property called target property. The target property is used to identify the window where the document referenced by the link's URL loads.
The most popularly used Internet Explorer browser, supports both anchor object and link object. Because of this association, the programmer might have a question in differentiating between the two. The href property of anchors object sets the anchor that represents the link and when the name property is set, it indicates a named anchor.
There is only one method present in the link object named handleEvent(). The argument given in this method is an event object, thus invoking the associated event handler for that event.
There is an anchor() method associated with the string object and, additionally, there is another method of string object called the link() method. The link() method of string object takes HREF attribute of link as parameter and creates a link to the given HREF.
This can be written as follows:
|
The above example generates HTML, thus creating a link for the current document with the given HREF.
The anchor object accesses the target of a hypertext link since it keeps track of all named offsets defined in respect to the HTML document. The anchor object has no associated properties, methods or events. It is actually a property of the document object. All the anchors of a particular document are contained in anchor array, so this is used for accessing anchor objects within a document. There is an anchor() method associated with the string object, used for creating an anchor in a current document.
This can be written as follows:
|
The above example creates the named anchor in the current document.
First Page: JavaScript Browser Objects