Your HostICan Community  


Go Back   Your HostICan Community > Programming & Design > Javascript / Java Applets

Javascript / Java Applets Are you a JavaScript guy? Do you need help with JavaScript? This is the place to talk about anything related to Java.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-11-2009, 05:55 AM
dileka's Avatar
dileka dileka is offline
Junior Member
 
Join Date: Feb 2009
Posts: 2
Default hosting links such as site map

How can I extract all links from a page. If anyone has a script for recursive extraction of links, please to share it. I have an idea to use a such script for the making of a something similar like site map.
Reply With Quote
  #2  
Old 05-11-2009, 08:50 AM
randy's Avatar
randy randy is offline
Senior Member
 
Join Date: Jan 2009
Posts: 110
Default Re: hosting links such as site map

This is a very useful JavaScript. In this script I use getElementById. Many people are not familiar with this function and when they do form used outdated function - document.FORM.Name.value
Here's the script:
HTML Code:
<html>
<head>
<script language="JavaScript1.2">
<!--
function extractlinks(){
if (document.all||document.getElementById){
if (document.all)
var links=document.all.tags("A")
else if (document.getElementById)
var links=document.getElementsByTagName("A")
var total=links.length
var win2=window.open("","","menubar,scrollbars,status")
win2.document.write("<h2>Total Links="+total+"</h2>")
for (i=0;i<total;i++){
win2.document.write('<a href="'+links[i]+'">'+links[i].innerHTML+'</a>')
}
win2.document.close()
}
}
//-->
</script>
</head>
<body>
text from a page<a href="link">link</a>text from a page<a href="link">link</a>text from a page<a href="link">link</a>text from a page<a href="link">link</a>text from a page<a href="link">link</a>text from a page<a href="link">link</a>text from a page<a href="link">link</a>text from a page<a href="link">link</a>text from a page<a href="link">link</a>text from a page<a href="link">link</a>text from a page<a href="link">link</a>text from a page<a href="link">link</a>text from a page<a href="link">link</a>text from a page<a href="link">link</a>text from a page<a href="link">link</a>text from a page<a href="link">link</a>
<p>
<button onClick="extractlinks()">Extract Links</button>
</body>
</html> 
Reply With Quote
Reply

Tags
hosting, links, map, site

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 03:45 PM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.

Copyright © 2003 - 2008 HostICan. All Rights Reserved.