Skip to content

Instantly share code, notes, and snippets.

@vishaltelangre
Created January 2, 2014 10:12
Show Gist options
  • Save vishaltelangre/8217253 to your computer and use it in GitHub Desktop.
Save vishaltelangre/8217253 to your computer and use it in GitHub Desktop.
Function to create iframes with ease
function createIframe(id, targetEle, src, content, style){
var iframe = document.createElement('iframe');
(iframe.frameElement || iframe).style.cssText = style || "width: 0; height: 0; border: 0";
iframe.id = id;
iframe.src = src || "javascript:false";
$(targetEle).append(iframe);
if(src) return iframe;
var doc = iframe.contentWindow.document;
doc.open().write(content);
doc.close();
return iframe;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment