【发布时间】:2018-11-01 13:33:17
【问题描述】:
我有一个 iframe 内联 src,例如:
let src = `data:text/html;charset=UTF-8,<html>
<body>
<p>Content</p>
</body>
</html>`
当页面加载时,我正在创建 iframe 并将其添加到页面正文:
let iframe = document.createElement("iframe")
document.querySelector('body').appendChild(iframe)
然后我将 src 设置为 iframe:
iframe.setAttribute('src', src)
如何获取 iframe 内容中呈现的宽度和高度并将其设置为 iframe 宽度和高度以及执行此操作的最佳方法是什么(使用 JS 或可能使用 CSS)
【问题讨论】:
-
使用 iframe 而不是 div 的目的是什么?跨域浏览器政策让这种事情头疼
-
可以获取iframe变量的innerHeight & innerWidth。
-
@dano,这是因为在那个 iframe 中实际上应该是电子邮件 html,它不应该依赖于其他样式。
标签: javascript html css iframe