如何处理Javascript中的ActiveX事件 [英] How to handle an ActiveX event in Javascript
问题描述
这是此处的回答。
我有一个自定义的ActiveX控件,它提出了一个需要在Web浏览器中由Javascript处理的事件(ReceiveMessage和msg参数)。历史上,我们已经能够使用以下仅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页面中,它可以正常工作,但是如果我们把它放在由< Form>
标签包裹的ASPX页面中,我们得到一个 MyControl是未定义的错误。我们尝试了以下变体:
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在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屋!