Show all Anchors in a file

[Total: 0    Average: 0/5]

This shows how to use JavaScript to search through an HTML file and find all the anchors (links) to other web pages.

Head Code:

<script type="text/javascript">
if (navigator.appName.indexOf("Miscrosoft") != -1) listanchors.nav=false
function listanchors(d) {
  newwin.document.writeln("<b>Navigation Window:<br>"+d.title+"</b>")
  newwin.document.writeln("<BR>Number of named anchors="+d.anchors.length+"<br><BR>")
  for(var i=0;i<d.anchors.length;i++) {
    var text
	var a=d.anchors[i]
	if (listanchors.nav) text=a.text
	else text=a.innerText
	if ((text==null) || (text==''))
	newwin.document.write('<a href="#''"'+' onClick="opener.location.hash='' 
   + + ''; return false;">')
defaultStatus="Click the Button!"

Body Code:

<a href="" onMouseOver="status='No Name For This One';return true;">To the first link</a>
<a name="Num2" onMouseOver="status='Name=Num2';return true;" href="">To the second one</a>
<a name="a_name" onMouseOver="status='Name=a_name';return true" href="">Third Choice</a>
<BR>There is fourth link here --->
<a name="lastA" onMouseOver="status='Name=lastA';return true" href=""></a>
<--- that you can not see
<input type="button" value="Click to begin the search" onClick="listanchors(document)">

Times Viewed: 2

Leave a Reply

Your email address will not be published. Required fields are marked *