如何获取iframe contentWindow在跨域的高度 [英] How to get iframe contentWindow height in cross domain

查看:1732
本文介绍了如何获取iframe contentWindow在跨域的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据自己的内容自动调整我的iframe高度,但在相同的领域,它与contentWindow.height正常工作,但在跨域的情况下,它的权限被拒绝访问iframe dom。

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.

推荐答案

对于现代浏览器,您可以使用 window.postMessage 函数在属于两个不同域的iFrames之间进行通信。

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

还有一些jQuery插件,它们用不支持 window.postMessage window.postMessage >。

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.

您可以从这里查看下面的页面(可以借用你需要的javascript):

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

Lutron - 压载选择工具

具有下拉列表的工具实际上是从单独的域加载到iFrame。然后根据内容的高度动态调整iFrame的大小。

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.

这篇关于如何获取iframe contentWindow在跨域的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆