如何在 Javascript 中处理 ActiveX 事件 [英] How to handle an ActiveX event in Javascript

查看:39
本文介绍了如何在 Javascript 中处理 ActiveX 事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是对此处的回答的后续.

我有一个自定义的 ActiveX 控件,它正在引发一个需要由 Web 浏览器中的 Javascript 处理的事件(带有msg"参数的ReceiveMessage").从历史上看,我们已经能够在不同的项目中使用以下仅限 IE 的语法来完成此操作:

I have a custom ActiveX control that is raising an event ("ReceiveMessage" with a "msg" parameter) that needs to be handled by Javascript in the web browser. Historically we've been able to use the following IE-only syntax to accomplish this on different projects:

function MyControl::ReceiveMessage(msg)
{
   alert(msg);
}

但是,当在埋有控件的布局中时,Javascript 无法找到该控件.具体来说,如果我们把它放到一个普通的 HTML 页面中它可以正常工作,但是如果我们把它放到一个由

标签包装的 ASPX 页面中,我们会得到一个MyControl is undefined"错误.我们尝试了以下变体:

However, when inside a layout in which the control is buried, the Javascript cannot find the control. Specifically, if we put this into a plain HTML page it works fine, but if we put it into an ASPX page wrapped by the <Form> tag, we get a "MyControl is undefined" error. We've tried variations on the following:

var GetControl = document.getElementById("MyControl");
function GetControl::ReceiveMessage(msg)
{
   alert(msg);
}

...但它会导致 Javascript 错误GetControl 未定义."

... but it results in the Javascript error "GetControl is undefined."

处理从 ActiveX 控件发送的事件的正确方法是什么?现在我们只对让它在 IE 中工作感兴趣.这必须是我们正在做的事情的自定义 ActiveX 控件.

What is the proper way to handle an event being sent from an ActiveX control? Right now we're only interested in getting this working in IE. This has to be a custom ActiveX control for what we're doing.

谢谢.

推荐答案

我能够使用以下脚本块格式使其工作,但我仍然很好奇这是否是最好的方法:

I was able to get this working using the following script block format, but I'm still curious if this is the best way:

<script for="MyControl" event="ReceiveMessage(msg)">
    alert(msg);
</script>

这篇关于如何在 Javascript 中处理 ActiveX 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆