Rohit Bajaj
asked on
Calculating the height of an iframe
Hi,
I am using the following code to determine the height of the contents an iframe. The issue is that it works on chrome.. But has random behaviour on safari :
What could be the issue.. I see sometimes whitespace below the iframe. The same iframe one time the height is calculated on rendering as 40px and some other random time as 140 px.
What could be the reason for this. This is happening only on safari on chrome its working fine..
This iframe is basically rendered inside my web application and i set the height properly using the above code after it has rendered.
Thanks
I am using the following code to determine the height of the contents an iframe. The issue is that it works on chrome.. But has random behaviour on safari :
document.addEventListener('DOMContentLoaded', function () {
var body = document.body, html = document.documentElement;
var height = Math.max(body.scrollHeight, body.offsetHeight,
html.clientHeight, html.scrollHeight, html.offsetHeight);
window.parent.postMessage({
name: 'resizeAttachmentView',
iframeId: body.dataset.iframeId,
height: height
}, '*');
});
What could be the issue.. I see sometimes whitespace below the iframe. The same iframe one time the height is calculated on rendering as 40px and some other random time as 140 px.
What could be the reason for this. This is happening only on safari on chrome its working fine..
This iframe is basically rendered inside my web application and i set the height properly using the above code after it has rendered.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.