title: Save the document generated by javascript
body: <p>Javascript can manipulate the document the browser is displaying, so the following: </p>
  
  <pre><code>&lt;script&gt;
      document.write("&lt;table&gt;&lt;tr&gt;&lt;td&gt;Hola&lt;/td&gt;&lt;td&gt;Adios&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;");
  &lt;/script&gt;
  </code></pre>
  
  <p>Will make the browser display a table just like if it was the original HTML document:</p>
  
  <pre><code>&lt;table&gt;
      &lt;tr&gt;
          &lt;td&gt;Hola&lt;/td&gt;
          &lt;td&gt;Adios&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Is there a way I can save/serve this document content? </p>
  
  <p>Currently we have some nicely generated reports using Ext-js, what I would like to do is to have the "text/html" version of it ( I mean, something that doesn't require javascript ) </p>
  
  <p>So at the end of the page I would add a button : "Save as blaba" and the document should display the text/plain version.</p>
  
  <p>The only way I could think right now is, to write the content into a javascript variable like:</p>
  
  <pre><code> var content = document.toString(); // or something magic like that.
   // post it to the server
  </code></pre>
  
  <p>Then post that value to the server, and have the server present that value.</p>
  
  <pre><code> &lt;%=request.getParameter("content-text")%&gt;
  </code></pre>
  
  <p>But looks very tricky. </p>
  
  <p>Is there an alternative?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Ok, I almost got it. Now I just need the new window to pop up so the option "would you like to save it shows" </p>
  
  <p>This is what I've got so far</p>
  
  <pre><code>&lt;script&gt;
      document.write("&lt;div id='content'&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;Hola&lt;/td&gt;&lt;td&gt;Adios&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;");
      function saveAs(){
          var sMarkup =  document.getElementById('content').innerHTML; 
          var oNewDoc = document.open('application/vnd.ms-excel');        
          oNewDoc.write( sMarkup + "&lt;hr&gt;" );
          oNewDoc.close();
      }
  &lt;/script&gt;
  
  &lt;input type="button" value="Save as" onClick="saveAs()"/&gt;
  </code></pre>
  
  <p>The line:</p>
  
  <pre><code>    var oNewDoc = document.open('application/vnd.ms-excel');        
  </code></pre>
  
  <p>Should specify the new content type, but it is being ignored.</p>