【问题标题】:InternetExplorer Input tag type text not converting to IHTMLInputTextElement in BHO?Internet Explorer 输入标记类型文本未在 BHO 中转换为 HTMLInputElement?
【发布时间】:2011-06-25 22:37:27
【问题描述】:

"sign in" to login.livevia msdn.com page 的过程中,DHTML 生成的表单似乎行为不端,因此找到第一个带有 tagName“输入”的IHTMLElement 元素并将其转换为IHTMLInputElement 字段可以看到它有type="text",但是在查询时无法提供IHTMLInputTextElement 接口。其他任何输入字段都没有为其特定类型提供接口。

相比之下,在点击http://gmail.com 时,相同的过程也可以正常工作。

我不知道这个错误的来源,DHTML,login.live,月亮在错误的阶段? 在 IE7 和 IE8 上遇到相同的问题,因此似乎不是特定于版本的。 无论 IE 兼容模式如何,都会遇到相同的问题。

这是一个简单的例子

TSharedField Factory( CComPtr<IHTMLElement>& _Element )
{
CComQIPtr<IHTMLTextAreaElement> TextAreaField = _Element;
if (TextAreaField)
    return TSharedField(new Text(TextAreaField));

CComQIPtr<IHTMLInputTextElement> TextField = _Element;
if (TextField)
    return TSharedField(new Text(TextField));

CComQIPtr<IHTMLInputButtonElement> ButtonField = _Element;
if (ButtonField)
    return TSharedField(new Button(ButtonField));

CComQIPtr<IHTMLInputFileElement> FileField = _Element;
if (FileField)
    return TSharedField(new CWebField_File(FileField));

CComQIPtr<IHTMLInputHiddenElement> HiddenField = _Element;
if (HiddenField)
    return TSharedField(new Hidden(HiddenField));

CComQIPtr<IHTMLOptionButtonElement> BooleanField = _Element;
if (BooleanField)
    return TSharedField(new Boolean(BooleanField));

CComQIPtr<IHTMLSelectElement> SelectionField = _Element;
if (SelectionField)
    return TSharedField(new Select(SelectionField));

CComQIPtr<IHTMLInputImage> ImageField = _Element;
if (ImageField)
    return TSharedField(new Image(ImageField));

// Added for debug, only gets hit on login.live
std::wstring type;
HRESULT hr;
DOM_SIMPLE_GET_STRING( type, _Element, get_tagName, hr);

::OutputDebugString( type.c_str() );
if( type == L"INPUT" ){
    CComQIPtr<IHTMLInputElement> Input = _Element;
    if( Input){
        DOM_SIMPLE_GET_STRING( type, Input, get_type, hr);
        ::OutputDebugString( (type+L"\n").c_str() );
    }
}
    return TSharedField();
}

【问题讨论】:

    标签: internet-explorer dhtml bho


    【解决方案1】:

    嘿 Greg,我在使用 Input 元素的 BHO 工作,所以你的问题引起了我的兴趣。经过一些广泛的测试后,我遇到了和你一样的问题。在 DocumentComplete 事件触发并且您尝试对其 IHTMLInputTextElement 接口的名称和密码元素进行 QI 时,它会失败。但是,我发现您可以使用 HTMLInputTextElementEvents 接口成功接收它们,这使我得出结论,此问题的原因是 MSHTML 中的错误造成的。请放心,月相是 A-OK。现在,让 IE 团队参与调查的机会有多大?

    【讨论】:

    • 似乎没有创建更专业的界面,所以我已经使用 IHTMLInputElement 并检查 get_type 值。由于我需要支持 IE6-IE9,我想这是修复之前最好的解决方法。
    【解决方案2】:

    也许,那个 type=text 输入元素没有完全初始化(没有准备好)。

    你检查过文档的就绪状态吗?

    如果您从 BHO 启动 DHTML 文档修改操作,则可能会出现此类问题。

    安全简单的替代方法是使用 window.execScript 函数来执行操作。

    【讨论】:

    • 感谢您的建议。进行检查并延迟,直到文件注册为准备就绪,并没有解决问题。作为 window.execScript 运行并不能真正解决问题。
    猜你喜欢
    • 1970-01-01
    • 2015-01-27
    • 1970-01-01
    • 1970-01-01
    • 2015-04-13
    • 2012-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多