create iframe in javascript code example

Example 1: html iframe example

<iframe src="http://www.codegrepper.com"></iframe>

Example 2: put html in iframe

<iframe srcdoc="<html><body>Hello, <b>world</b>.</body></html>"></iframe>

Example 3: document.createElement('iframe');

var ifrm = document.createElement('iframe');
ifrm.setAttribute('id', 'ifrm'); // assign an id

//document.body.appendChild(ifrm); // to place at end of document

// to place before another page element
var el = document.getElementById('marker');
el.parentNode.insertBefore(ifrm, el);

// assign url
ifrm.setAttribute('src', 'demo.html');