2013-10-28 77 views
1

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

我试过用html agilitypack,一个非常好的lib,但当然它不考虑css渲染。尝试使用WPF webbrowser,但它似乎无法获取每个元素的字体大小,并且对于其中的很多元素,它会返回一个百分比。

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

任何想法?

+0

你试过了'currentStyle'财产? http://stackoverflow.com/questions/1905766/how-determine-css-text-of-each-node-in-html/1905782#1905782 – CodingIntrigue

+0

你为什么需要这个?你想要什么时候的背景很重要? – Liam

+0

上下文从网页中提取文本文章,因此了解被解析文本的大小很重要。 – user2927491

回答

0

试试这个:

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"); 
+0

谢谢,但它必须是一个服务器端过程,我需要C#知道网页中的文本大小... – user2927491

+0

如果我理解你的话,你不能只用C#来完成......你为什么不使用它AJAX? – inon