How to get generated HTML-code?

Discussion in 'JavaScript' started by TriKri, Jul 11, 2007.

  1. #1
    Hello! Is there someway to get the HTML-code which represent the page at a current time?

    for example:

    <html>
      <head>
        
    <script type="text/javascript">
    function load()
    {
      document.body.innerHTML += "Hello!"
    }
    </script>
    
      </head>
      <body onload="load()">
        
      </body>
    </html>
    Code (markup):
    After the page has loaded the actual HTML-code really looks something like this:

    <html>
      <head>
        
    <script type="text/javascript">
    function load()
    {
      document.body.innerHTML += "Hello!"
    }
    </script>
    
      </head>
      <body onload="load()">
        
      Hello!</body>
    </html>
    Code (markup):
    But is there some way to extract that HTML-code from the document and not the one that was initially loaded (the second code and not the first of the two I wrote here)?
     
    TriKri, Jul 11, 2007 IP
  2. Cloudberries

    Cloudberries Peon

    Messages:
    74
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you use window.document.documentElement.innerHTML - this should give you the current contents of the HTML document

    Or - did you just mean "How do I view the source code with the newly updated content, added in by Javascript?"

    If you're using Firefox, I've noticed a peculiarity with the "View source" functionality. If you select "View source" from the top menu bar, it won't show up any modifications (like "Hello!") that Javascript has made.

    But, if you select all the code on the page (do a right-click "select all") and then right-click "view selection source" this will show up the changes that Javascript has made.
     
    Cloudberries, Jul 11, 2007 IP
  3. TriKri

    TriKri Peon

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Awsome! I'll just use document.documentElement.innerHTML. :cool: I'll check that "view selection source" in FF, seems weird, but anyway :p
     
    TriKri, Jul 11, 2007 IP