title: How to download a complete html code with .html format?
body: <p>HI I am creating a dynamic <code>html</code> section and I have two buttons: <strong>preview</strong> and <strong>download</strong>.</p>
  
  <p>The <strong>preview</strong> is fine working. As for the second button, i.e. <strong>download</strong>, I want to make the action of the button such that if the <strong>download</strong> button is clicked, it triggers a download of all html code stored in the variable <code>rohit</code> with <code>.html</code> format.</p>
  
  <p>How do I do this? Please let me know. I had searched for it on Google but could not find a way to do it. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(document).ready(function(){
    var rohit = "&lt;h2&gt;Hello i m Dynamic Heading &lt;/h2&gt;";
       $('.preview').on('click', function(){
              var myWindow = window.open('', "rohit", "width=800, height=400", '_blank');
     myWindow.document.write(rohit);
          });
      
      
       $('.download').on('click', function(){
           alert(rohit);
              //  here download code with html format how to do this .
          });
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;button class="preview"&gt;click to preview&lt;/button&gt;
  &lt;button class="download"&gt;CLick to Download&lt;/button&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>and <strong>Jsfiddle</strong> <strong><a href="http://jsfiddle.net/9n5v8m26/" rel="nofollow">Link here</a></strong></p>