有没有办法将 javasript 中的属性动态添加到 BHO 中注册的对象?
IE
// javascript
window.bho
window.bho.foo = "New property";
抛出“对象不支持此属性或方法”
解决方案必须适用于 .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);
}
}