【发布时间】:2011-08-20 01:57:08
【问题描述】:
任何人都可以帮我写一个脚本..或获得价值的方法
height : 1196px;
width: 284px;
来自计算的样式表(webkit)。我知道 IE 和往常一样不同。我无法访问 iframe(跨域)——我只需要高度/宽度。
我需要的屏幕截图(红色圈出)。如何访问这些属性?
来源
<iframe id="frameId" src="anotherdomain\brsstart.htm">
<html id="brshtml" xmlns="http://www.w3.org/1999/xhtml">
\--I WANT THIS ELEMENTS COMPUTED BROWSER CSS HEIGHT/WIDTH
<head>
<title>Untitled Page</title>
</head>
<body>
BLA BLA BLA STUFF
</body>
</html>
\--- $('#frameId').context.lastChild.currentStyle
*This gets the actual original style set on the other domain which is "auto"
*Now how to getComputed Style?
</iframe>
我得到的最接近的是这个
$('#frameId').context.lastChild.currentStyle
这给了我 HTML 元素的实际样式,即“自动”,这是真的,因为这就是它在 iframed 文档上的设置。
如何获得所有浏览器用来计算滚动条和检查元素值的计算样式?
使用 Tomalaks 的答案,我为 webkit 变出了这段可爱的脚本
window.getComputedStyle(document.getElementById("frameId"), null).getPropertyValue("height")
或
window.getComputedStyle(document.getElementById("frameId"), null).getPropertyCSSValue("height").cssText
结果 150 像素
与
相同$('#frameId').height();
所以我让他们在头部添加一个 'brshtml' 的 id - 也许这会帮助我更轻松地选择元素。 Webkit 检查现在向我显示 html#brshtml 但我无法使用 getelementbyid 选择它
【问题讨论】:
-
查看本页的“相关”部分...
-
听起来您可能想使用 element.offsetWidth 和 element.offsetHeight 属性,但实际上很难从帖子中说出您真正想要什么。
-
是的——我可以使用任何我想要的脚本。对于生活,我无法获得这些值..我想根据计算的样式设置 iframe 高度..如果我使用 jquery 来获取 iframes.docuemnt.height - Bleee- 访问被拒绝 - 看在上帝的份上 - 那么如何浏览器知道它的 1196px 吗??!它就在那里!那我怎么得到它:D漂亮请
-
我已经阅读了 SO 的(几篇 * 几篇)文章——我无法得到有效的答案
-
您实际需要哪个高度和宽度? iframe 窗口的大小与 iframe 内容的大小有关吗?请澄清。
标签: javascript html css cross-domain computed-style