Below is the code snippet:
var dynamicIframe;
dynamicIframe = document.createElement('iframe');
dynamicIframe.src = 'http://example.com/file.zip';
dynamicIframe.style.display = 'none';
document.body.appendChild(dynamicIframe);
Check out the live demo: http://jsfiddle.net/USSXF/2/
Your code is not functioning correctly because you are passing an entire HTML string into the createElement
function (using "jQuery style" :)
), which is invalid. The correct parameter for this function should be a string representing the tag-name (such as 'div'
, 'iframe'
, 'p'
, etc.).
Learn more about document.createElement
here.