简体   繁体   English

处理HTML / Javascript中ActiveX控件的属性触发的事件

[英]Handling events fired by Property of ActiveX Control in HTML/Javascript

The following HTML object represents an ActiveX control that has a property named SubSystemA: 以下HTML对象表示具有名为SubSystemA的属性的ActiveX控件:

<object id="MainObject"
    CLASSID="CLSID:2C327457-D12F-4FC4-BFC2-D7C029003D07"
    width="0px" height="0px"
    >
    <embed name="MainObject"></embed>
</object>

SubSystemA is a COM object implementing some interface with methods, properties, and events. SubSystemA是一个COM对象,它实现了一些方法,属性和事件的接口。 SubSystemA's methods and properties are easily callable from Javascript, but since SubSystemA is a property of MainObject, I am not sure how to attach an event handler to SubSystemA's events. SubSystemA的方法和属性可以从Javascript轻松调用,但由于SubSystemA是MainObject的属性,我不知道如何将事件处理程序附加到SubSystemA的事件。

I know of two ways to handle events fired by MainObject: 我知道有两种方法来处理MainObject触发的事件:

<script type="text/javascript">
    function MainObject::SomeMainEvent(arg1, arg2)
    {
         // Event handling logic
    }
</script>

and

<script type="text/javascript" for="MainObject" event="SomeMainEvent(arg1, arg2)">
    // Event handling logic
</script>

But how would one handle an event for MainObject.SubSystemA? 但是如何处理MainObject.SubSystemA的事件呢?

I found that the following works: 我发现以下工作:

<object id="MainObject"
    CLASSID="CLSID:2C327457-D12F-4FC4-BFC2-D7C029003D07"
    width="0px" height="0px"
    >
    <embed name="MainObject"></embed>
</object>

<script type="text/javascript">
    function MainObject.SubSystemA::SomeSubSystemEvent(arg1)
    {
         // Event handling logic
    }
</script>

and am currently looking for a way to adapt the <script for="..." event="..."> syntax, since it seems to allow later binding where the working syntax does not. 我目前正在寻找一种方法来适应<script for =“...”event =“...”>语法,因为它似乎允许后来的绑定工作语法没有。

The easiest way I have found to do events on a subobject that allows javascript complient implementation of events is to implement attachEvent and detachEvent yourself; 我发现在允许javascript兼容实现事件的子对象上执行事件的最简单方法是自己实现attachEvent和detachEvent; simply save the IDispatch* of the function that is passed in, and then iterate through them and call Invoke with DISPID=0 on each one. 只需保存传入的函数的IDispatch *,然后遍历它们并在每个函数上调用DISPID = 0的Invoke。

For MainObject itself you'll probably have to use connection points, which work a bit differently. 对于MainObject本身,您可能必须使用连接点,这有点不同。

FireBreath abstracts all of that for both IE and Firefox, including the creation of seperate COM objects. FireBreath为IE和Firefox提取所有这些内容,包括创建单独的COM对象。 Might be worth a look 可能值得一看

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM