show html preview in a frame using javascript

<html>
 <head>
  <title>show html preview in a frame using javascript</title>
 </head>
 <body style="background:lightgray">
  <p>Click the button to test:</p>
  <button onclick="populateIframe()">Preview</button>
  </br>
  <textarea id="edit" style="height:200px;width:200px">
   <html>
    <body>
     hi
    </body>
   </html>
  </textarea>
  </br>
  <iframe id="frame">
  </iframe>
  <script>
function populateIframe() {
 var ifrm = document.getElementById("frame");
 ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
 ifrm.document.open();
 var content=document.getElementById("edit").value;
 ifrm.document.write(content);
 ifrm.document.close();}
 populateIframe();
  </script>
 </body>
</html>

Comments

Popular posts from this blog

How to write data into a excel file using vbscript

Format date as yyyy-mm-dd using vbscript