Search code snippets, questions, articles...

Load or preview html to Iframe using Javascript only

You can use the code to preview your HTML code to iframe or writing your HTML, CSS and Js code to iframe
var html = '';
html += '<!DOCTYPE html>\n';
html += '<html lang="en">\n';
html += '<head>\n';
html += '</head>\n';
html += '<body>\n';
html += '<div>Hello World we are here...</div>';
html += '</body>\n';
html += '</html>';

(document.getElementById("iframe_id").contentWindow.document).write(html);
(document.getElementById("iframe_id").contentWindow.document).close();
Was this helpful?
0 Comments
Programming Feeds
Learn something new everyday on Devsheet