Prev: FAQ Topic - Why is my Ajax page not updated properly when using an HTTP GET request in Internet Explorer? (2010-03-07)
Next: Javascript Toolbox - Table Sort utility - Column Width cannot be set.
From: Garrett Smith on 7 Mar 2010 03:53 I want to set the toElement property on a custom event, however it cannot be done automatically. If what I read is correct, the reason for this is that the property is a reference. Here is a demonstration of the problem. <html> <head> <title>blah</title> </head> <body> <script type="text/jscript"> document.body.onmouseout = function () { var from = event.fromElement; from = from && from.nodeName; alert("fromElement: " + from); }; document.body.fireEvent("onmouseout" /*, {fromElement: document.documentElement}*/);</script> </body> </html> I have noticed that if the event is generated by the user, then the toElement property is set. I have also noticed that if the argument to createEventObject is an event object with a toElement property, that the toElement reference is used. The problem is that the toElement property seem only to be set from a user-generated event. Is there any code that will cause IE to set the toElement property? The reason I want this to work is to test my "getRelatedTarget" function. I believe the function works (it seems to work as I am using it), but the unit tests are failing because in IE, the `toElement` property is null, and not the object that the test is expecting it to be. -- Garrett comp.lang.javascript FAQ: http://jibbering.com/faq/
From: Thomas 'PointedEars' Lahn on 7 Mar 2010 09:29
Garrett Smith wrote: > I want to set the toElement property on a custom event, however it > cannot be done automatically. If what I read is correct, the reason for > this is that the property is a reference. Possible. > Here is a demonstration of the problem. Your example source code does not relate to what you are describing here. > <html> > <head> > <title>blah</title> > </head> > <body> > <script type="text/jscript"> > document.body.onmouseout = function () { > var from = event.fromElement; > from = from && from.nodeName; > alert("fromElement: " + from); > }; > document.body.fireEvent("onmouseout" /*, > {fromElement: document.documentElement}*/);</script> The error message I am getting (80004002) in IE 6.0.2800.1106 when using that second argument and the documentation for fireEvent() indicate that fireEvent() cannot be used that way. You can use it for event delegation, but not creation. > </body> > </html> > > I have noticed that if the event is generated by the user, then the > toElement property is set. I have also noticed that if the argument to > createEventObject is an event object with a toElement property, that > the toElement reference is used. But you are not using createEventObject() here. However, if you use it you can see that `toElement' is special: document.body.onmouseover = function () { /* null */ window.alert(window.event.toElement); }; var e = document.createEventObject(); e.toElement = document.body; /* null */ window.alert(e.toElement); document.body.fireEvent("onmouseover", e); However: document.body.onmouseover = function () { /* 2 */ window.alert(window.event.button); }; var e = document.createEventObject(); e.button = 2; /* 2 */ window.alert(e.button); document.body.fireEvent("onmouseover", e); > The problem is that the toElement property seem only to be set from a > user-generated event. That appears to be a correct observation. > Is there any code that will cause IE to set the toElement property? I do not think so; this is very likely due an MSHTML bug as other properties can be set that way. Meaning that the documentation is correct that the property is read/write sometimes, but it neglects to mention that the property then has a setter that still prevents changes to its value. PointedEars -- realism: HTML 4.01 Strict evangelism: XHTML 1.0 Strict madness: XHTML 1.1 as application/xhtml+xml -- Bjoern Hoehrmann |