今天解决了一个IE11的兼容问题,关于attachEvent的。

  控件是ActiveX的,需要监听一个控件相关的事件。蓦然发现attachEvent在IE11不支持了...attachEvent不是IE专有的么?是啊,这是IE专属呃,这么多年,不离不弃。IE的attachEvent不支持捕获阶段的事件处理程序,并且同一个处理程序能添加多次。非标准的IE专属,在IE11,彻底自己抛弃了...

  IE11不再任性,走上了标准化的道路...

  问题至此并没有解决,使用addEventListener仍然没有监听到ActiveX的事件,最后在MSDN找到了解决方案:

<!DOCTYPE html>
<html>
    <head>
        <title>TestEvent Example HTML</title>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <script language='javascript' for="testAxEvent" event="testEvent(szType, szValue)">
        // Test 1 - statically load the script (This is the basis for the hack)
        // Works on IE8, IE9, IE10 and IE11
            var MSG = document.getElementById("msg");
            MSG.innerHTML = szType + " : " + szValue;
        </script>
    </head>
    <body>
        <table>
            <tr>
                <td>
                    <OBJECT ID='testAxEvent' CLASSID='CLSID:BA19A985-C93E-491B-B801-2EB7F903C8CE' codebase="testAxEvent.cab"></OBJECT>
                </td>
            </tr>
            <tr><td  height='30'></td></tr>
            <tr>
                <td align=center><font size=5><div id='msg'></div></font>    
            </tr>
        </table>
    </body>
</html>
监听ActiveX事件@IE11

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-08
  • 2022-12-23
  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
  • 2021-04-20
猜你喜欢
  • 2021-09-29
  • 2021-11-22
  • 2022-12-23
  • 2022-12-23
  • 2021-10-27
  • 2021-09-19
  • 2021-06-02
相关资源
相似解决方案