简体   繁体   English

跨网域iframe自动调整高度

[英]cross domain iframe adjust height automatically

I searched over google as well as few answers from stackoverflow but none of teh solution worked for me. 我搜索了谷歌以及从stackoverflow的几个答案,但没有一个解决方案为我工作。 Is there any working solution available , 有没有可行的解决方案,

Thanks you very much 非常感谢你

Rohit. 罗希特

The IFRAME need to send to the main page its body size. IFRAME需要将其主体大小发送到主页。

For modern browsers you can use parent.postMessage from the IFRAME and have a listener in the main page to receive the value and resize the IFRAME. 对于现代浏览器,您可以使用IFRAME中的parent.postMessage ,并在主页上有一个侦听器来接收值并调整IFRAME的大小。

For older browsers you can use tricks like passing data ie through windows.name or the window.location.hash But with those tricks you will have to poll with a setInterval to check for changes. 对于较旧的浏览器,您可以使用诸如通过windows.namewindow.location.hash传递数据之类的技巧,但是使用这些技巧,您将不得不使用setInterval进行轮询以检查更改。

@Rohit I would suggest taking a look at this website. @Rohit我建议您看一下这个网站。 This should solve your problem http://benalman.com/projects/jquery-postmessage-plugin/ 这应该可以解决您的问题http://benalman.com/projects/jquery-postmessage-plugin/

A functional demo can be found here: http://benalman.com/code/projects/jquery-postmessage/examples/iframe/ 可以在此处找到功能演示: http : //benalman.com/code/projects/jquery-postmessage/examples/iframe/

I plan to use this technique for a project of mine after I saw that I'm able to calculate the height across domain using query and postmessage. 在看到能够使用查询和后消息计算整个域的高度后,我计划将这种技术用于我的一个项目。 What's nice is it'll default to document.location.hash for older browsers. 好的是,对于较旧的浏览器,它将默认为document.location.hash。

尝试从iframe调用父窗口函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM