Using VBScript I can sink the events perfect using
"Sub Obj_Event()" syntax. The Engine Queries GetItemInfo with the
SCRIPTINFO_ITYPEINFO flag and everything is well. However I can not get
events sunk in JScript. After researching for a while, I found a kb article
explaining that Obj_Event syntax was ripped out in version 3.0 of JScript.
So, I tried
obj.event = obj_event ;
AND
obj.event ="obj_event()";
IE style, and I get an "Object doesn't support this property or method." In
the Knowledge base article it says that events should be sunk in the <SCRIPT
FOR="obj" EVENT="event"> syntax. Obviously this is not a possibility in
non-browser hosts.
So, how do you sink events in JScript without a web browser? The only thing
I can think of is to implement some kind of script aware interface, in each
class, that actual calls the functions through the IActiveScript's
IDispatch. What a bunch of bull. Can someone please shed some light on an
efficient(perhaps built-in) method of sinking events using JScript? I'd
really like to enable IE style assignment, but have no clue how they're
doing it.
btw, I'm using the JScript 5.0 Engine.
Thanks,
Ryan
You are correct, the "object.onevent" syntax is a property of the _object_,
not the script engine. IE's objects simply have properties which are set to
the functions which should be called when the event is fired -- rather than
the traditional COM connection points, the script code itself informs the
object what it should do when the event goes.
Obviously you can't do this to an arbitrary object unless you have the
source code and choose to rewrite it to have all those extra properties.
To get the VBScript-style implicit event handling in JScript, use :: instead
of _. For instance:
function button1::onclick()
{
// whatever
}
Note that this only works if the JScript engine has been put into CONNECTED
state. This syntax doesn't work in IE because IE doesn't put the JS engine
into connected state. (The IE team did not want to support an event binding
syntax different from Navigator's syntax, for better compatibility.)
Eric
Ryan Tomayko <ry...@neo.rr.com> wrote in message
news:#9TtD29g#GA....@cppssbbsa02.microsoft.com...
Eric
Andrew Nosenko <cap...@meadroid.com> wrote in message
news:er7oOvSh#GA.262@cppssbbsa03...
> Hi Eric,
>
> As far as I may guess, IBindEventHandler is behind the following IE-style
event
> binding schema:
> <script>
> function window.onload() { alert("Loaded!" }
> </script>
> JScript does QI for IBindEventHandler on 'window', right?
>
> Thanks,
> Andrew Nosenko.
>
>
> Eric Lippert (Microsoft Scripting Dev) <Eri...@Microsoft.com> wrote in
message
> news:OY2o2ORh#GA....@cppssbbsa02.microsoft.com...