Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

quick question on ah ref tags 1

Status
Not open for further replies.

cajchris

Programmer
Oct 13, 2005
57
GB
is there any way that I can collate all a href links within the body of an html page and store them in some sort of list.

thanks
cajchris
 
This works for me:

Code:
<html>
<head>
	<script type="text/javascript">
	<!--
		onload = collateLinks;

		function collateLinks() {
			var outputStr = '';
			var allLinks = document.getElementsByTagName('a');
			for (var loop=0; loop<allLinks.length; loop++) {
				outputStr += 'Link URL: ' + allLinks[loop].href + '\nLink Content: ' + allLinks[loop].innerHTML + '\n\n';
			}
			alert(outputStr);
		}

	//-->
	</script>
</head>

<body>
	<a href="somelink.html">link text</a>
	<a href="somelink2.html">more link text</a>
</body>
</html>

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top