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>