code_junkie

How to handle an ActiveX event in Javascript

Nov 11th, 2011
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. function MyControl::ReceiveMessage(msg)
  2. {
  3. alert(msg);
  4. }
  5.  
  6. var GetControl = document.getElementById("MyControl");
  7. function GetControl::ReceiveMessage(msg)
  8. {
  9. alert(msg);
  10. }
  11.  
  12. <script for="MyControl" event="ReceiveMessage(msg)">
  13. alert(msg);
  14. </script>
  15.  
  16. var clock = new ActiveXObject("Clocks.clock");
  17. var extendedClockEvents = clock.ExtendedClockEvents();
  18. // Here you assign (subscribe to) your callback method!
  19. extendedClockEvents.ScriptCallbackObject = clock_Callback;
  20. ...
  21. function clock_Callback(time)
  22. {
  23. document.getElementById("text_tag").innerHTML = time;
  24. }
  25.  
  26. function onEventHandler(arg1, arg2){
  27. // do something
  28. }
  29.  
  30. window.onload = function(){
  31. var yourActiveXObject = document.getElementById('YourObjectTagID');
  32. if(typeof(yourActiveXObject) === 'undefined' || yourActiveXObject === null){
  33. alert('Unable to load ActiveX');
  34. return;
  35. }
  36.  
  37. // attach events
  38. var status = yourActiveXObject.attachEvent('EventName', onEventHandler);
  39. }
  40.  
  41. function MyControl::ReceiveMessage(msg)
  42. {
  43. alert(msg);
  44. }
Add Comment
Please, Sign In to add comment