I figured this would be pretty simple -- just implement an ActiveX control with connection points. Unfortunately, it doesn't work. Internet Explorer complains thus:

This is because JavaScript can't sink COM events. This seemed odd to me, because the same approach works when you try to use the XMLHttpRequest object. As it turns out, XMLHttpRequest doesn't implement "events" as COM events at all. They're actually properties that accept IDispatch pointers. JavaScript functions are marshalled to ActiveX as objects that implement IDispatch and having a method named "call".

Simply put, this is what we need to do to enable ActiveX events to be handled by JavaScript using the syntax shown above:

1) Implement a property in the ActiveX control that accepts an IDispatch pointer.

3) When you want to invoke the event, construct a VARIANTARG containing the parameters you want to pass to the event in reverse order. Add a pointer to your own IDispatch implementation as the last element in the array.

Dan,
On the contrary, this approach works perfectly well both in IE6 and IE7 (at least it does on XP; I haven't tested it on Vista). I used VS2005 for development.
What kind of trouble are you running into?

Hi Ragesh,
The javascript function is not called at all.
I have implemented a simple ATL object and not a control and done the steps you detailed above.
The dispId is always 1 when I call the property from the javascript code.
Can you please post a sample code?

Hi Ragesh,
Thank you for your help.
In fact I just found what was the issue today, on your article you are referring to the pEventHandler, which is actually not documented, I assumed it to be the IUnkown interface of the object, but in fact it should be declared as CComPtr&lt; IDispatch &gt; pEventHandler and assigned at the STDMETHODIMP CTestCtrl::putref_OnStateChanged(IDispatch* newVal) in a way that pEventHandler = newVal.
Your code is then working...
Regards,