admin管理员组文章数量:1391925
How to get the height and width of an iframe
, executing a script from
outside the iframe
?
I want to find its dimensions.
Javascript solutions weled.
How to get the height and width of an iframe
, executing a script from
outside the iframe
?
I want to find its dimensions.
Javascript solutions weled.
Share Improve this question edited Apr 22, 2015 at 17:33 dbarnes 1,8633 gold badges18 silver badges33 bronze badges asked Apr 22, 2015 at 17:28 PrasangaPrasanga 1,0382 gold badges15 silver badges35 bronze badges2 Answers
Reset to default 2Using pure javascript:
document.getElementsByTagName('iframe')[0].getAttribute('width');
document.getElementsByTagName('iframe')[0].getAttribute('height');
getBoundingClientRect
returns an object with the following keys: left
, top
, right
,bottom
, x
, y
, width
und height
.
const { width, height } = document.querySelector("iframe").getBoundingClientRect();
console.log(width, height);
<p>Example for iframe dimensions</p>
<iframe src="https://www.example."></iframe>
本文标签: javascriptHow to get the height and width of an iframeStack Overflow
版权声明:本文标题:javascript - How to get the height and width of an iframe - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744671563a2618854.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论