How to get HTML Source in Javascript code ?

Discussion in 'JavaScript' started by ciocan, Feb 12, 2007.

  1. #1
    Hello guys,

    I can't find a way to get the document source with js.
    Using document.body.innerHTML , I only get html source from the body, but I need full html source of the page.

    Any idea?

    Thanks.
     
    ciocan, Feb 12, 2007 IP
  2. phper

    phper Active Member

    Messages:
    247
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Use XmlHttpRequest and request for the page, then getResponseText() to get the content.
     
    phper, Feb 12, 2007 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    Or:
    
    document.getElementsByTagName('html')[0].innerHTML
    
    Code (javascript):
     
    nico_swd, Feb 12, 2007 IP
  4. bart.nicolotti

    bart.nicolotti Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    And if I couldn't request the page again, i.e. if I've posted data that changed the status of the database and re-posting would change it again? I'm using on error to send the error happened on the browser to the server log, but as the page is dynamically generated the line is not enought, because it doesn't match the php/jsp line.

    Many thanks, best regards
     
    bart.nicolotti, Nov 11, 2008 IP