Attaching to ActiveX Events in Internet Explorer 9
I have embeded an ActiveX control via an HTML <option>
element in Internet Explorer that plays video from a Cisco video server.
To make the player play I write a callback function for the ActiveX control's onPlayerLoaded event.
The code I have works in IE 7 - 9, but only when I use Microsoft's proprietary attachEvent function.
JavaScript example:
if(this.axClient.attachEvent)
{ this.axClient.attachEvent("onPlayerLoaded", on开发者_高级运维PlayerLoadedEventHandler); }
The standard's nazi in me really wants to use addEventListener instead like so ...
if(this.axClient.addEventListener)
{ this.axClient.addEventListener("onPlayerLoaded", onPlayerLoadedEventHandler, false); }
else if(this.axClient.attachEvent)
{ this.axClient.attachEvent("onPlayerLoaded", onPlayerLoadedEventHandler); }
(Starting with IE 9, addEventListener is supported.)
Unfortunately when I use addEventListener the callback function never gets called.
I do not have a lot of experience with consuming ActiveX controls, so I'm assuming there are some nuances about them that I might be missing.
Given that ActiveX is a Microsoft proprietary technology is it a fair assumption that we should continue to use attachEvent instead of addEventListener with them? (Is there something inherent in ActiveX that forces us to continue using attachEvent?)
Or is this something the publisher of the AciveX control can remedy? (For example, are there new practices for ActiveX that take advantage of IE 9 more standard-friendly nature.)
Or given that ActiveX is proprietary, should I just not worry too much about standards with them ...? ;)
I looked into this same question while trying to make addEventListener work with my FireBreath plugins. Since FireBreath plugins work on all major browsers, I was excited that in IE9 addEventListener support would make it so that everything could work exactly the same.
Imagine my shock when I discovered that none of the APIs on the plugin/activex control -- none of them -- were called or notified in any way when addEventListener was called on the object. attachEvent uses an interface on the ActiveX control called Connection Points, and on Firefox we have to implement the addEventListener and removeEventListener methods ourselves, but on IE9 it just intercepts those calls, doesn't return an error, and they disappear into the void.
{sarcasm}Amazing! Way to go Microsoft!{/sarcasm}
精彩评论