i need to autoheight an iframe with a cross domain src, i tried with javascript, but I get an “Access Denied” when I try to get the height of iframe contentWindow. anyone knows any method?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
ItzWarty is right: the parent page cannot communicate with the child document, even to find out its height. Back in 2008, Michael Mahemoff posted a detailed overview of Cross-Domain Communication with IFrames that may provide you with some guidance.
Hope is on the way, however – HTML5 includes an improvement to this situation called “Cross-document messaging” that is supported in Firefox 3, Safari 4, Chrome 2, Opera 9.2 and even IE… 8. If your users are using only those supported browsers, you could use it.
Perhaps you could set the “scrolling” attribute on the IFRAME element to “auto” by default and test for window.postMessage – if it succeeds, set “scrolling” to “no” and use a function to size the IFRAME accordingly.
I recently dealt with a similar issue (parent page from domain.tld framing a page on blog.domain.tld) but I was able to use “the old document.domain hack” that Mahemoff described to get by, although it’s not supported in Opera.
Good luck.