Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get iframe contentWindow height in cross domain

i want to auto adjust my iframe height according to their content but in same domain it's work properly with contentWindow.height but in case of cross domain its permission denied for accessing iframe dom.

like image 654
tanujdave Avatar asked Sep 08 '10 12:09

tanujdave


People also ask

How do I set the iframe height to fit content?

You can use the JavaScript contentWindow property to make an iFrame automatically adjust its height according to the contents inside it, so that no vertical scrollbar will appear.

How do I access cross domain iframe?

To access cross-domain iframe, the best approach is to use Javascript's postMessage() method. This method provides a way to securely pass messages across domains.


1 Answers

For modern browsers you can use the window.postMessage function to communicate between the iFrames belonging to two different domains.

There are also several jQuery plugins that wrap window.postMessage with older URL hashing techniques for browsers that don't support window.postMessage. It makes the usage of the technology transparent to the end user.

You can look at the following page (and probably borrow the javascript you need) from here:

Lutron - Ballast Selection Tool

The tool with the dropdowns is actually being loaded from a separate domain into an iFrame. The iFrame is then dynamically resized based on the height of the inner content.

like image 168
Justin Niessner Avatar answered Oct 09 '22 00:10

Justin Niessner