如何获得加载后的某个元素的实际宽度/高度,其宽度/高度最初由PERCENTAGE设置? [英] How to get actual width/height of some element after loading whose width/height originally set by PERCENTAGE?
问题描述
我有一个iframe,其内容指向一个HTML文档。
在该HTML文档中,有一个指向PDF文档的EMBED元素。此EMBED最初的宽度和高度设置为PERCENTAGE(例如: width:100%; height:100%
)。
我的问题是:
在加载iframe之后,如何检索实际,绝对宽度和高度EMBED元素的任何单位px,pt,em等)。
我一直在尝试所有可能的js属性(宽度,高度,样式:clientWidth,clientHeight ,offsetWidth,offsetHeight ...)和jQuery(例如outerWidth,outerHeight等),但它看起来没有希望。 解决方案
$ b
document.getElementById(id)。clientHeight
document.getElementById (id)。clientWidth
id是EMBED元素的唯一ID。
关于这方面的更多信息:
https://developer.mozi lla.org/en/DOM:element.clientHeight
https://developer.mozilla.org/zh/DOM:element.clientWidth
I have an iframe, whose content points to an HTML document.
In that HTML document, there's an EMBED element pointing to a PDF document. This EMBED originally set up with width and height in PERCENTAGE (such as: width: 100%; height: 100%
).
My question is:
After the iframe has been loaded, how can I retrieve the actual, absolute width and height (in any unit px, pt, em etc.) of the EMBED element.
I've been trying on all possible js properties (width, height, style: clientWidth, clientHeight, offsetWidth, offsetHeight...) and in jQuery as well (such as outerWidth, outerHeight etc.) but it seems hopeless.
This should return what you need:
document.getElementById("id").clientHeight
document.getElementById("id").clientWidth
id is a unique ID of the EMBED element.
For more about this:
https://developer.mozilla.org/en/DOM:element.clientHeight
https://developer.mozilla.org/en/DOM:element.clientWidth
这篇关于如何获得加载后的某个元素的实际宽度/高度,其宽度/高度最初由PERCENTAGE设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!