An ActiveX control is being loaded conditionally based on browser and other factors.
In order to handle events from the ActiveX control, a simple jquery .bind('Event', ...) won’t work. Instead, it seems to me that my only choice is to use <script ... for='myPlugin' event='Event'></script> style binding.
1) It seems that if the script tag statically part of the HTML and is loaded before the control exists on the page, then IE won’t fire the event
2) Hard-coding the object IDs is unacceptable if there needed to be (dynamically) multiple instances of the plugin
But when I add the following code, I get “‘param1’ is undefined” immediately, before the event should fire (I’m almost certain that it is not in response to the event firing).
$('HEAD').append($('<script language="javascript" ' +
'type="text/javascript" for="myPlugin" event="Event(param1)">' +
'$('#myPlugin').triggerHandler("jQueryBoundEvent", [ param1 ]);' +
'<' + '/script>'));
From the web, I’ve gathered that jQuery interfere’s with adding script tags and rather eval()s them. That would explain the unbound param1 and the immediate execution of the script. The script’s for and event attributes are lost during the eval().
Is there another approach to load the plugin dynamically, and attach to it’s events without hardcoding the handlers?
=======
Alternatively, it seems from various posts that even though $.bind() doesn’t work for ActiveX and XPI plugins, that attachEvent() or addEventListener() should work. Is this the case? I haven’t been able to confirm it for a dynamically added plugin.
Try
appendTo('head')instead of$('head').append(...I know JQuery say they’re basically identical except for the order, but IE disagrees and prefers
appendTo()when injecting scripts into the head.Try this: