BHO exposing javascript method works in IE 9+ but fails in earlier versions

孤街醉人 提交于 2019-12-08 03:47:39

问题


I'm making a BHO that exposes method to JavaScript.

It works okey in IE 9 and IE 10, but fails in IE 8 with RuntimeBinderException: "mshtml.HTMLWindow2Class" does not contain "signJson".

Code is mostly based on live reload IE extention.

Here is a way that function is injected into window:

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

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

What's different about about mshtml.HTMLWindow2Class in IE 8 from IE 9? What is a proper way to inject method into it?


回答1:


Found an answer on Stack Overflow. You just have to change code to this:

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);
    }
}


来源:https://stackoverflow.com/questions/16795322/bho-exposing-javascript-method-works-in-ie-9-but-fails-in-earlier-versions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!