user900140
user900140

Reputation: 11

How to add properties to object registered in BHO from javascript?

Is there a way to dynamically add properties from javasript to object registered in BHO?

i.e

// javascript
window.bho
window.bho.foo = "New property";

throws "Object doesn't support this property or method"
solution must works on .NET 2.0 Framework

// C#
public class ScriptableObject: IScriptableObject
{
    WebBrowser webBrowser;
    HTMLDocument document;

    public ScriptableObject(WebBrowser browser)
    {
        webBrowser = browser;
        document = webBrowser.Document as HTMLDocument;
    }

   // some methods or properties here
}


public class BHO : IObjectWithSite
{
    ...
    public void OnDownloadComplete()
    {
        document = webBrowser.Document as HTMLDocument;
        window = document.parentWindow as IHTMLWindow2;            
        IScriptableObject so = new ScriptableObject(webBrowser);

        // Adding our custom namespace to JavaScript land.
        PropertyInfo myProp = winExpando.AddProperty("bho");
        myProp.SetValue(winExpando, so, null);
    }

}

Upvotes: 1

Views: 330

Answers (0)

Related Questions