Reputation: 37934
I am allowing a part of my site to be shown in another site (different domain).
My concern is to set the height of iframe to the height of its content. I could use this solution, but my case is cross browser case, so this doesnot work.
I tried to get the height of iframe by:
window.parent.document.getElementById('id_iframe').contentDocument.body.scrollHeight;
but this is giving only the visible height.
What am I missing?
Upvotes: 0
Views: 48
Reputation: 944455
You can't use JavaScript to access content the user has loaded from another domain. It would be a security risk.
With the cooperation of the other site, you can receive a message (via postMessage
) sent by the other site when its load
event fires that tells you its height (and then you can resize in response to that).
It could also sent new heights when resize
events fire in it.
Upvotes: 1