How can I detect a websites page source code?

Discussion in 'JavaScript' started by chengcj, May 8, 2006.

  1. #1
    Assume my homepage has a button and a textbox. When I press the button, the textbox would show the page source code of "www.google.com" (or any other web page source code)

    Of course, I haven't got the page source code before hand, or else I can just copy and paste the page source code to the textbox...

    Would you please tell me how to use javascript to do that?

    Thank you very much for helping me^^

    May I ask a further question...

    How about if I only want the first 100 charcters or the first 15 lines of the source code to be in my textbox?

    How would I do that with javascript?
     
    chengcj, May 8, 2006 IP
  2. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You need to write a php script to access the third party page using fopen and echo the result to the screen (a very simple task).

    Then write an ajax application to call the php script and display the resulting output into your text area.

    Its pretty simple to do. :)
     
    mad4, May 8, 2006 IP
  3. NetMidWest

    NetMidWest Peon

    Messages:
    1,677
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You can get the code with the JavaScript Source's source viewer. How to put it in the textbox - or manipulate it otherwise - is a matter of programming.

    They have lots of great snippets.
     
    NetMidWest, May 8, 2006 IP
  4. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #4
    A neater solution than mine. Doesn't work for me though (IE7).:)
     
    mad4, May 8, 2006 IP
  5. frisby

    frisby Well-Known Member

    Messages:
    1,378
    Likes Received:
    39
    Best Answers:
    0
    Trophy Points:
    140
    #5
    You even don't need ajax, if you allow to refresh page when someone type url.

    Nutshell from brain:
    $code = file_get_content("url");
    <textarea><?=$code?></textarea>

    Just pseudocode...
     
    frisby, May 8, 2006 IP
  6. NetMidWest

    NetMidWest Peon

    Messages:
    1,677
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Bummer...

    I have used it a few times as a template filling pagebuilder - check off menus, footers, and etc. - input the title, desc, kw, location of a content file, and via a simple cgi or php script up pops a cut and paste html page...

    chengcj also mentioned Google. With the javascript, the request is by the user, not the script (in its basic form).
     
    NetMidWest, May 8, 2006 IP
  7. chengcj

    chengcj Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thank you very much every body! But may I further ask another question...

    How about if I don't want the entire source code? I would only want the first 100 characters of the source code to be in my textbox....
     
    chengcj, May 8, 2006 IP
  8. MrSupplier

    MrSupplier Peon

    Messages:
    141
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    using ajax will be safer for you, but not sure if it wont be browser security restrictions for loading different domain's data...
     
    MrSupplier, May 8, 2006 IP
  9. torunforever

    torunforever Peon

    Messages:
    414
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #9
    torunforever, May 8, 2006 IP
  10. NetMidWest

    NetMidWest Peon

    Messages:
    1,677
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Here is the basic implementation of what I mentioned earlier...
    http //www netmidwest.com/source.html
    I found it handy for seeing what was in mouseover or 0 second redirects, too.
    I wonder what the logic was for disabling it.
     
    NetMidWest, May 8, 2006 IP