最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get the height and width of an iframe - Stack Overflow

programmeradmin3浏览0评论

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 badges
Add a ment  | 

2 Answers 2

Reset to default 2

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

发布评论

评论列表(0)

  1. 暂无评论