Results 1 to 2 of 2

Thread: Get specified page source as string

  1. #1
    Join Date
    Nov 2010
    Posts
    28
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Get specified page source as string

    I would like to get the source of any page I specify as a JavaScript string. I can use

    window.location = "view-source:http://www.dynamicdrive.com";

    to print the source code to the user, but that's not what I want to do.

    Can I get the entire source of a page (e.g. http://www.dynamicdrive.com) as a JavaScript string, so that I can analyze and extract the parts which I'm interested in.

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    I'd image you could use something like this:
    Code:
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
     $.ajax({
      url: "view-source:http://www.custom-anything.com"
      ,dataType: "text"
      ,success: function(data){
        $("#div").text(data);
       }
      ,error: function(xhr,erstr){ alert(erstr); }
     });
    });
    </script>
    , though it doesn't work in present form (I get an error about a non-functional http protocol handler). I'll keep tinkering with it, though there are others here who know more about javascript.

    Edit:

    This can be done from php (and other server-side languages), but with js, you may be stuck behind the same-domain rule.
    (although, at present, I can't get it to work at all.)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •