DelphiFAQ Home Search:

Accessing all links in a document with JavaScript

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

Question:

Is there a way to access all the links in a document with javascript?

Answer:

You can access all the links in a document using the documents.links array. The link itself will display the href value, or you can specify the href@} property directly. You can get to the link text using the @[link.innerText property.

<BODY>
<A href="http://www.yahoo.com/">Hello</A>
<SCRIPT LANGUAGE=JAVASCRIPT><!--
for (var i=0; i < document.links.length; i++) {
  var li = document.links[i];
  alert(li.href);
  alert(li.innerText);
}
//-->
</SCRIPT>
</BODY>

Content-type: text/html

Comments:

2012-03-17, 12:53:22
anonymous from United Kingdom  
here is one javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI=document.getElementsByTagName('img'); DIL=DI.length; function A(){for(i=0; i-DIL; i++){DIS=DI[ i ].style; DIS.position='absolute'; DIS.left=(Math.sin(R*x1+i*x2+x3)*x4+x5)+'px'; DIS.top=(Math.cos(R*y1+i*y2+y3)*y4+y5)+'px'}R++}setInterval('A()',5); void(0);

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: