dynamically load iframe in javascript

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');

If you ever need to load an iframe in Javascript you can use this following snippet ?

BETA Snippet explanation automatically generated by OpenAI:

No explanation generated yet.

Snippet By Tony Lea

·

Created June 12th, 2021

·

Report Snippet