如何通过iframe中的javascript获取iframe的高度?那么有多个iframe的网页呢? [英] How to get the height of an iframe with javascript from inside the iframe? What about pages with multiple iframes?

查看:104
本文介绍了如何通过iframe中的javascript获取iframe的高度?那么有多个iframe的网页呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法通过从iframe内部执行脚本来检测iframe的高度和宽度?
我需要根据iframe的不同高度/宽度动态定位iframe中的某些元素。

Is there a way to detect the height and width of an iframe, by executing a script from inside the iframe? I need to dynamically position some elements in the iframe according to the different height/width of the iframe.

如果有多个iframe会有什么区别在同一页?即每个iframe想要找到自己的维度。

Would there be any difference if there are multiple iframes in the same page? i.e. each iframe wants to find its own dimensions.

欢迎使用Javascript或jquery解决方案。

Javascript or jquery solutions welcomed.

谢谢! p>

Thanks!

<iframe src='http://example.com' width='640' height='480' scrolling='no' frameborder='0' longdesc='http://example.com'></iframe>

iframe必须嵌入其他网站,正如下面的一个答案所提到的,

The iframes have to be embeded on other sites, and as mentioned by one of the answers below, I've hit permission problems.

推荐答案

如果您的iframe的页面及其父页面是从不同的域提供的(意思是你不能访问父页面的DOM属性从iframe页面),然后我认为这是一样的,当你试图找出视口高度。

If your iframe’s page and its parent page are served from different domains (meaning you can’t access the parent page’s DOM properties from the iframe page), then I think it’s the same as when you’re trying to work out the viewport height.

为此,请参阅:

  • Get the browser viewport dimensions with JavaScript

或者可能这样:

  • http://andylangton.co.uk/articles/javascript/get-viewport-size-javascript/

这篇关于如何通过iframe中的javascript获取iframe的高度?那么有多个iframe的网页呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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