开发者

Jquery iframe crossdomain dynamic height

Is this even p开发者_Go百科ossible with jquery only with no bulky plugins?

I know there are lots of plugins and alternatives, i'm searching for the shortest, robustest & most cleanest (preferably relying on jquery)

Here basic jsfiddle to tryout your thoughts: http://jsfiddle.net/3vPJd/


I have to go with "This is not possible" due to the fact that the parent page cannot get the height of the 3rd party page since it is from a different domain than the parent page.

Edit: It is possible to do this if you have some control of the 3rd party page.

I personally would just use the method they already have implemented, it doesn't require jQuery, you just have to include the frame.js.

At that point, all you need is a method on the parent page that listens for when the hash changes and resizes the iframe accordingly, which is also already written by the site you linked. it is a very clean solution already, no real need to modify it. It can be found here.


This little library will do what you want. It uses postMessage to talk between the iFrame and the parent, so works cross domain. It also uses MutationObserver and EventListeners to detect changes to the content and keep the iFrame correctly sized.

https://github.com/davidjbradshaw/iframe-resizer

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜