How to get the height of a iframe?

by elise_daugherty , in category: Javascript , 7 months ago

How to get the height of a iframe?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by ryleigh , 7 months ago

@elise_daugherty 

You can get the height of an iframe using JavaScript by accessing the contentWindow and scrollHeight properties of the iframe element.


Here is an example code snippet to get the height of an iframe:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
// Get the iframe element
var iframe = document.getElementById('your-iframe-id');

// Get the content window of the iframe
var iframeWindow = iframe.contentWindow;

// Get the scroll height of the iframe content
var iframeHeight = iframeWindow.document.body.scrollHeight;

// Log the height of the iframe
console.log("Height of the iframe: ", iframeHeight);


Replace 'your-iframe-id' with the id of your iframe element in the above code. This code will log the height of the iframe content in the console.

Related Threads:

How to get the iframe height in firefox?
How to get real iframe body height?
How to get height of pdf document load in iframe?
How to update the height of the iframe?
How to change the height of an iframe with javascript?
How to make dynamic height of iframe?