Question:

Javascript help??? 10 points?

by  |  earlier

0 LIKES UnLike

How can I use a javascript script in an html page to get the html source of another remote page? I want to use a script to parse another webpage's source. How can I get the basic html as a string.

 Tags:

   Report

3 ANSWERS


  1. Unfortunately, or fortunately, depending on your perspective, the browser's native security model disallows this. Same-origin policy demands that requests for XML or HTML content be from within the same domain of origin. If they're not, then you can't "play with" the response content. You can populate an iframe with content from another site (domain), but you can NOT manipulate (or even query via the DOM) the contents of that page.

    In order to parse a page from another domain, you must handle the page on the server side.


  2. there is no such command, but i'm pretty sure stealing a source like that is illegal

  3. <html>

    <head>

    <script type="text/javascript">

    function vsrc(){

    alert( frames[0].document.body.innerHTML );

    }

    </script>

    </head>

    <body>

    <iframe width=100 height=100 src="test2.html" name="vsrc" id="vsrc" style="display: none;" ></iframe>

    <input type="button" value="view source" onclick="vsrc();" />

    </body>

    </html>

    This code catches page test2.html via iframe and allows javascript to access it. Only problem with this method is that these pages must be on the same server or browsers block javascript access to frame for security reasons.

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.