使用 JavaScript 创建 IFRAME 的最佳实践是什么? [英] What is the best practice creating IFRAME using JavaScript?

查看:62
本文介绍了使用 JavaScript 创建 IFRAME 的最佳实践是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 JavaScript 创建 iframe HTML 元素的最佳做法是什么?

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

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

我在开发 Firefox 插件时遇到了这个问题,但用法与开发网页完全相同.我不使用 jQuery.

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

推荐答案

你可以试试像这个:-

<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> 

这篇关于使用 JavaScript 创建 IFRAME 的最佳实践是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆