I'm trying to generate synthetic Javascript events in an Internet Explorer extension, and I'm having trouble getting the fromElement property to stick. Here's an excerpt of my code:
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
What am I doing wrong here? eObj.fromElement should be equal to from, but it doesn't seem to be getting set.
var o = document.createEventObject(); o.fromElement = document.getElementByID(locator); return o;
– Delciedelcinafrom
word is a reserved word in c#, it doesn't caused you an error? – Gailfrom
is a conditional keyword, not a reserved word. The parser is smart enough to know when you're using it as a keyword vs an identifier. – Autry