从IE中的HtmlElement的Dom获取IHTMLStyle3 [英] getting IHTMLStyle3 from the Dom of HtmlElement in IE

查看:603
本文介绍了从IE中的HtmlElement的Dom获取IHTMLStyle3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个窗体上的System.Windows.Form.WebBrowser控制。我浏览了浏览器对象到URL。

I've got a System.Windows.Form.WebBrowser control on a form. I navigate that browser object to a url.

在页面加载完成后,我想分析该加载页面的各个方面。

Once the page has finished loading, I'd like to analyse various aspects of the page that loaded.

在我特别有兴趣,看看哪些是IHTMLStyle3界面上找到的属性writingMode。

In particular I'm interested to see the attribute 'writingMode' which is found on the IHTMLStyle3 interface.

是这样的:

public void MyMethod(HtmlElement element)
    {
        IHTMLElement2 element2 = element.DomElement as IHTMLElement2;
        IHTMLStyle3 style3 = element2.currentStyle as IHTMLStyle3;

        string writingMode = style3.writingMode;
    ...



现在的问题是,该节日礼物值为null。我想这意味着IHTMLElement2.currentStyle不支持IHTMLStyle3。

The problem is, the style3 value is null. I assume this means IHTMLElement2.currentStyle doesn't support IHTMLStyle3.

我试过也试着铸造IHTMLELement.style。不过,虽然这并愉快地转换为IHTMLStyle3它似乎并没有遏制,因为它是被应用到HTML元素的样式。

I've tried also tried casting IHTMLELement.style. But while that does cast happily as IHTMLStyle3 it doesn't seem to contain the style as it's been applied to the Html element.

推荐答案

看一下文档,我相信你需要得到 IHTMLElement2.currentStyle 属性作为常规风格属性只内联样式。这种差异在讲话表明了 IHTMLElement2.currentStyle

Looking at the documentation, I believe you need to get the IHTMLElement2.currentStyle property as the regular style property is the inline style only. This difference is indicated in the remarks for IHTMLElement2.currentStyle:

通过的属性
返回的值IHTMLStyle和
IHTMLCurrentStyle接口不同,当一个对象的样式没有设置
直列
。例如,如果
A网页的作者只能通过
链接或嵌入的样式表,和

A段红的颜色属性不在线,那么
IHTMLCurrentStyle ::颜色属性
返回值红色,
IHTMLStyle :: get_color属性并
没有返回值。然而,如果
作者指定下面的例子中
表色属性内联的值,如在
,两者
IHTMLCurrentStyle ::颜色和
IHTMLStyle :: get_color性能
返回值红色。

The values returned by the properties of the IHTMLStyle and IHTMLCurrentStyle interfaces differ when the style of an object is not set inline. For example, if the author of a Web page sets the color property of a paragraph to red only through a linked or embedded style sheet, and not inline, then the IHTMLCurrentStyle::color property returns the value red, and the IHTMLStyle::get_color property does not return a value. However, if the author specifies the value of the color property inline, as in the following example, both the IHTMLCurrentStyle::color and IHTMLStyle::get_color properties return the value red.

currentStyle 提供的 IHTMLCurrentStyle 接口,当用于查询 IHTMLCurrentStyle2 会给你 writingMode 根据您的要求。

currentStyle provides a IHTMLCurrentStyle interface, which when queried for IHTMLCurrentStyle2 will give you writingMode as you require.

这篇关于从IE中的HtmlElement的Dom获取IHTMLStyle3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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