Exforsys.com
 
Home Tutorials JavaScript
 

JavaScript Browser Objects

 

JavaScript Link and Anchor Objects

Page 2 of 2


Link Object:

Link 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.



Properties of Link Object:

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.


Methods of Link Object:

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:



exforsys =" Welcome To Training".link("http://www.exforsys.com/training/") documet.write(exforsys)



The above example generates HTML, thus creating a link for the current document with the given HREF.


Anchor Object:

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:



example="Exforsys".anchor("test")
document.write(
example)



The above example creates the named anchor in the current document.




First Page: JavaScript Browser Objects


Read Next: JavaScript Applet Objects



 

 

Comments



Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2009 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape