获取 HTML 元素字体大小



我想获取网页中html元素的字体大小,例如<p>标签。即使对于没有 styleclass 属性的元素,这也应该是有效的,因此它必须知道动态继承的 css 属性。

我尝试过使用 html agilitypack,这是一个非常好的库,但它当然不考虑 css 渲染。也尝试使用 WPF 网络浏览器,但似乎它无法获取每个元素的字体大小,并且对于其中许多元素,它返回一个百分比。

Javascript getComputedStyle()不适合,因为所有这些都应该运行服务器端。

有什么想法吗?

试试这个:

Element.prototype.getStyle = function (prop) {
    if (document.defaultView) 
        return document.defaultView.getComputedStyle(this, null)[prop];
    else 
        return this.currentStyle[prop];
}

叫:

document.getElementById("div1").getStyle("font-size");

最新更新