/    Sign up×
Community /Pin to ProfileBookmark

Defining event handlers for ActiveXObjects in IE

(This question has been asked before, about three years ago, and didn’t receive an answer. I’m hoping someone’s found a solution since then!)

I have a COM (automation, activex) object, that generates events, that I want to capture in JavaScript in Internet Explorer. I know that the events are being generated, and making it back to my script, because the following works:

<object id=”foo” classid=”clsid:…” ></object>
<script language=”javascript”>
function foo::OnEvent() { alert(‘Boo!’) }
// …other code to call methods on ‘foo’
</script>

However, I want to create the object using ActiveXObject:
var myobj = new ActiveXObject(‘…’)

and then associate my event handler function with ‘myobj’. I have tried every syntactic variation I can think of with no success, and can find no documentation on doing it this way. So…

  • if it’s possible, does anyone know how please?

  • or can anyone confirm if this is definitely not possible?

  • if it’s not possible, what are the downsides (if any) to using <object> to create the object, instead of ActiveXObject?
  • Many thanks for any help,
    Scott

    to post a comment
    JavaScript

    3 Comments(s)

    Copy linkTweet thisAlerts:
    @thelittlebomberJan 07.2010 — Did you get the answer? Could you send it to me?? I need this for a project too and can't find the answer anything.. I did find a project on codeproject, but can't really figure out what to do...

    Codeproject article
    Copy linkTweet thisAlerts:
    @KorJan 07.2010 — <i>
    </i>myobj.onclick=[B]function(){[/B][I][COLOR="Green"]//whichever here: functions, statements...[/COLOR][/I][B]}[/B]
    Copy linkTweet thisAlerts:
    @JustMeInMDFeb 04.2012 — I figured out how to sink events from ActiveX Objects created by the 'new ActiveXObject' JavaScript statement in IE. See the following link (scroll down to the post by JustMeInMD).

    http://social.msdn.microsoft.com/Forums/en-AU/iewebdevelopment/thread/bb5db2d7-aa05-49a6-bfaf-b6f32913ae8e

    You basically use an eval statement to dynamically define the event handler.
    ×

    Success!

    Help @ScottM spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.1,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,
    )...