简体   繁体   中英

What is the best practice creating IFRAME using JavaScript?

What is the best practice creating an iframe HTML element using JavaScript?

 var iframe = document.createElement("iframe");
 iframe.setAttribute("sandbox", "")
 iframe.setAttribute("src", url);

I faced the question while developing Firefox plugin, but usage is quite the same as developing a web page. I do not use jQuery.

You can try like this :-

<script type="text/javascript">
function abc() {
  iframe = document.createElement("IFRAME");
  iframe.setAttribute("src", "http://example.com/");
  iframe.style.width = "640px";
  iframe.style.height = "480px";
  document.body.appendChild(iframe);
}
</script> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM