0

Possible Duplicate:
Can Javascript read the source of any web page?

Can somebody please guide me to write a javascript snippet that fetches page details i.e page title,body content,and images just from link.

Well i have wrote a javascript that fetches source code from the posted link.I can always use getElementBytagName to get the required tags.I just wanted to know if there is a better way to do so.

<html>
<head>

<script type="text/javascript">
function changed(obj)
{
   get_information(obj.value);
}

function get_information(link) 
{ 
var xhr
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xhr=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xhr=new ActiveXObject("Microsoft.XMLHTTP");
  }
xhr.open("GET", link, true); 
xhr.onreadystatechange = function() { 
if (xhr.readyState === 4) 
{ 
alert(xhr.responseText); 
} 
};
 xhr.send(null);
 } 


</script>

</head>
<body>
<input type="text" onchange="changed(this)"/>
</body>
</html>

no i dont want the same page to be edited,i need to fetch the other page details from its link

Community
  • 1
  • 1
sambit
  • 3
  • 3

1 Answers1

0

Do you just want to get the title/body/content/images on the current page?

Something like this may work:

<html>
<head>
    <title>fetch</title>
    <script type="text/javascript">
        function showtitle(){
            var title=document.getElementsByTagName('title');
            alert(title[0].innerHTML);
        }
    </script>
</head>
<body>
    <span onclick="showtitle();">get</span>
</body>
</html>

Otherwise if you want to retrieve a new title/body/etc and update the page without reloading, you will have to use some sort of ajax request. Perhaps jQuery or the ultimate ajax object.

DarthJDG
  • 16,511
  • 11
  • 49
  • 56
Adam MacDonald
  • 1,958
  • 15
  • 19