Gre*_*reg 33 javascript c# internet-explorer mshtml
我正在尝试在Internet Explorer扩展中生成合成Javascript事件,并且我无法获取fromElement属性.这是我的代码的摘录:
MsHtml.IHTMLDocument4 doc4 = ... // the document object
Object o = null;
MsHtml.IHTMLEventObj2 eObj =
(MsHtml.IHTMLEventObj2)doc4.CreateEventObject(ref o);
// string that specifies the from element, e.g. "document.getElementById('id1')":
string locator = ...
object from = doc4.Script.GetType().InvokeMember("eval",
BindingFlags.InvokeMethod,
null,
doc4.Script,
new object[] { locator });
// from now holds a ref to an object that implements the IHTMLElement interface
eObj.fromElement = from;
IHTMLElement el = eObj.fromElement;
// el == null
Run Code Online (Sandbox Code Playgroud)
我在这做错了什么?eObj.fromElement应该等于from,但它似乎没有设置.
只是在黑暗中胡乱射击,但这可能是因为您将“null”对象传递给 CreateEventObject 方法吗?如果你改变这个呢:
Object o = null;
Run Code Online (Sandbox Code Playgroud)
对此:
Object o = new Object();
Run Code Online (Sandbox Code Playgroud)
在你的例子的第3行?