Thursday, December 17, 2015

JS ActiveX Events Explained, in all IE Versions. Part 1

Just a note for the younger developers: Yes, activeX are just for IE.

It seems that there is a lot of questions about activeX and the behaviour of mouse events on this type of components.

To start, let me just explain that activeX (in general), behave like a completely separate object and doesn't work in the same processa as IE.
The only mouse events exposed in the activeX are the ones that the developer of the activeX component chose to implement. So, when you try to hook the mouse events in your page, (using js of course), you should use attachEvent method, but if your IE version does not support this method, then you should turn to this deprecated html tag:
<script event="EventName" for="objectId" language="language">

For more details; https://msdn.microsoft.com/en-us/library/aa242436%28v=vs.60%29.aspx
You can choose to code a javascript method to implement this feature. For the activeX ctrl, and event Connect:
            var scriptEventConnect = $("script[for='" + ctrl.id + "']");
            if (scriptEventConnect != null && scriptEventConnect.length == 1){
                scriptEventConnect.empty(); }
            var s = document.createElement("script");
            s.language = "JScript";
            var a = document.createAttribute("for");
            a.value = ctrl.id;
            s.setAttributeNode(a);
            s.event = "Connect(lSourceId, sType)";
            s.innerHTML = ".............RIGHT HERE THE EVENT HANDLER CODE........ ";          
            (head || document.body).appendChild(s);
            

So, by now you should knowthe right way to use events that are exposed in the activeX. I love JQuery, but it seems that is not the rigth way of handling activeX events. It's not a JQuery related problem, activeX are not multibrowser, so....

You must be sure about the events that are exposed by the activeX and their arguments.

No comments: