Skip to content Skip to sidebar Skip to footer

Error In IE When Manually Calling Event Handler, Given Certain Conditions

Preface Please note, I'm not looking for a code solution, but rather insight into why this may occur. The error occurs in IE (tested 7 & 8), but not Firefox, Chrome, Safari.

Solution 1:

As to "why" it was implemented this way, there's probably no answer from the outside. A good example is when former IE developer, the inventor of innerHTML, faces problems with innerHTML itself.

Asking why is also unnecessary because

  1. You don't often call event handlers with parameters explicitly
  2. You can work around the issue (as you stated in your question)

Another thing to note is that your analogy is too specific. The issue is not restricted to the assignment expression, you can reproduce it with other types of expressions:

undefined === elem.onclick( true )
typeof elem.onclick( true )
elem.onclick( true ) - 1
alert(elem.onclick( true ))

Solution 2:

Have you tried using the instructions found here? He suggests using code like this:

var fireOnThis = document.getElementById('someID');
var evObj = document.createEvent('MouseEvents');
evObj.initMouseEvent( 'click', true, true, window, 1, 12, 345, 7, 220, false, false, true, false, 0, null );
fireOnThis.dispatchEvent(evObj);

Solution 3:

Try some function that actually has one parameter and actually returns something. See if it produces an error too. It may have something to do with parameters and a function default return value. Try it and post the results back, please.

EDIT

If the function does not get called, the problem could be in the resolution of the property onclick. It may be somehow you are not actually calling your defined function, but the code finds some other build in IE object when you pass true as parameter. In any case this behavior is out of any specifications and so we may call it bug. Of those IE has plenty as you can see from my own questions.

IE 8 absolute positioned element outside its parent clipping problem

IE8 bottom:0 in position:absolute behaves like position:fixed


Post a Comment for "Error In IE When Manually Calling Event Handler, Given Certain Conditions"