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

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

问题描述

我有iframe(跨域)与src从Facebook,Twitter等等我需要获得高度的iframe,但我有问题:权限被拒绝访问属性'文档'。请帮我解决这个。非常感谢!

I have iframe(cross domain) with src from facebook, twitter or etc. I need to get height of iframe but i got issue: "Permission denied to access property 'document'". Please help me to resolve this. Many thanks!

推荐答案

几个问题。首先, iframe 的高度可能不是你想要的。我的意思是明确设置在您控制的页面的HTML代码,并且可以通过任何Javascript手段容易访问和修改。您之后看到的是内部 iframe中页面的高度。如果是这样,简单的答案是你不能,至少不能与外部服务,如Facebook / Twitter。

Couple issues. First, the height of the iframe is likely not what you want. I mean that's set explicitly in the HTML code of the page you control and is readily accessible and modifiable through any Javascript means. What it appears you are after is the height of the page inside the iframe. If that's the case, the simple answer is you can't, at least not with external services like Facebook/Twitter.

由于安全原因,可以轻松地传递消息从子项到父项,但不是从父项到子项,除非在两个文档中的JavaScript 中构建了通信路径。在现代浏览器中有一个 postMessage 协议。 https://developer.mozilla.org/en/DOM/window.post消息 。但是,在这种情况下它是完全无用的,除非你正在通信的文档被设置为处理一个传入的postMessage,据我所知Twitter / Facebook经常不是。

Due to security reasons, one can easily pass messages from child to parent, but not from parent to child, unless a communication pathway has been built into your javascript in both documents. There is a postMessage protocol for handling this in modern browsers. https://developer.mozilla.org/en/DOM/window.postMessage . But, it's wholly useless in this case unless the document you are communicating with is setup to handle an incoming postMessage, which to my knowledge Twitter/Facebook frequently are not.

如果父文档可以与来自不同域的儿童自由交流,那么任何 javascript都可以有效地在您登录的任何网站上执行任何系列命令。这种安全隐患是可怕的,令人遗憾不可能。

If a parent document could freely communicate with children from different domains, then any javascript could effectively execute any series of commands on any site you're logged in as. The security implications of that are frightening and thankfully not possible.

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

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