Error in IE when manually calling event handler, given certain conditions

前端 未结 3 713
不知归路
不知归路 2021-01-31 11:25

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 no
相关标签:
3条回答
  • 2021-01-31 12:15

    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 ))
    
    0 讨论(0)
  • 2021-01-31 12:19

    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

    0 讨论(0)
  • 2021-01-31 12:24

    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);
    
    0 讨论(0)
提交回复
热议问题