【问题标题】:BHO exposing javascript method works in IE 9+ but fails in earlier versionsBHO 暴露 javascript 方法在 IE 9+ 中有效,但在早期版本中失败
【发布时间】:2013-06-22 07:09:22
【问题描述】:

我正在制作一个向 JavaScript 公开方法的 BHO。

它在 IE 9 和 IE 10 中运行良好,但在 IE 8 中失败并出现 RuntimeBinderException"mshtml.HTMLWindow2Class" does not contain "signJson"

代码主要基于live reload IE extention

这是函数注入窗口的一种方式:

    public void InjectScriptResource(dynamic window)
    {
        var windowEx = (IExpando)window;

        if (windowEx.GetProperty("signJson", BindingFlags.Default) == null)
        {
            windowEx.AddProperty("signJson");
            window.signJson = this;
        }
    }

IE 8 中的mshtml.HTMLWindow2Class 与 IE 9 有什么不同?将方法注入其中的正确方法是什么?

【问题讨论】:

    标签: c# internet-explorer-8 bho


    【解决方案1】:

    在 Stack Overflow 上找到 answer。您只需将代码更改为:

    public void InjectScriptResource(dynamic window)
    {
        var windowEx = (IExpando)window;
    
        if (windowEx.GetProperty("signJson", BindingFlags.Default) == null)
        {
            // windowEx.AddProperty("signJson");
            PropertyInfo p = windowEx.AddProperty("signJson");
            // window.signJson = this;
            p.SetValue(windowEx, this);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多