javascript Windows 7 上的 ActiveX 抛出“对象不支持属性或方法”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8066746/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ActiveX on Windows 7 throws "Object doesn't support property or method" error
提问by Glen J Fergo
We have a third-party ActiveX. It seems to be working fine on a Windows XP machine (Internet Explorer 7). However, when we test on Windows 7 Professional 64-bit (Internet Explorer 9), we receive an error message -- "Object doesn't support property or method '{methodname}'"
我们有第三方 ActiveX。它似乎在 Windows XP 机器(Internet Explorer 7)上运行良好。但是,当我们在 Windows 7 Professional 64 位 (Internet Explorer 9) 上进行测试时,我们收到一条错误消息——“对象不支持属性或方法 '{methodname}'”
Anyone knows what could be causing this?
有谁知道是什么原因造成的?
Is there a problem with the OS -- security is tighter, therefore the assembly needs something?
Is there a problem with the browser -- again, maybe security is tighter, therefore something in Tools >> Internet Options >> Security needs to be adjusted?
操作系统是否有问题——安全性更严格,因此程序集需要一些东西?
浏览器是否有问题——同样,可能安全性更严格,因此需要调整工具>> Internet 选项>> 安全性中的某些内容?
Thoughts or suggestions would be greatly appreciated!
想法或建议将不胜感激!
HTML:
HTML:
<body onload="OpenActiveX()">
<OBJECT id="OurActiveX"
name=”OurActiveX"
classid="clsid:43663B77-905C-4885-BC6B-4F57FE10A270"
VIEWASTEXT codebase="CS1504CAB.cab">
</OBJECT>
<script language="javascript">
function OpenActiveX()
{
try
{
alert(document.OurActiveX.Echo("Hi I am here."));
var sdata = document.OurActiveX.GetData();
if(sdata == "0"){
document.getElementById("barcodes").innerHTML = "No barcodes found.";
}
else if( sdata == "1"){
document.getElementById("barcodes").innerHTML = "Could not find the barcode reader.";
}
else{
var adata = sdata.split(":");
document.getElementById("barcodes").innerHTML = adata[0] + "<BR/>" + adata[1];
}
}
catch(Err)
{
alert(Err.description);
}
}
</script>
<div id="barcodes" />
回答by Windy
The error message indicates that the control is not available on the machine. You can check the security settings of IE on the client machine and verify the following security settings of IE to "Prompt" or "Enabled":
该错误消息表明该控件在机器上不可用。您可以在客户端机器上检查 IE 的安全设置,并验证 IE 的以下安全设置为“提示”或“启用”:
1) Download signed ActiveX controls 2) Run ActiveX Controls and plug-ins 3) Script ActiveX controls marked safe for scripting
1) 下载已签名的 ActiveX 控件 2) 运行 ActiveX 控件和插件 3) 脚本 ActiveX 控件标记为安全脚本
Protected Mode is On by default in Windows 7. Turn the proected mode offor try running IE as administrator can get rid of the security problem.
保护模式在 Windows 7 中默认开启。关闭保护模式或尝试以管理员身份运行 IE 可以摆脱安全问题。
Also, if you are using 64-bit IE, you need to make sure that the control supports 64-bit.
此外,如果您使用的是 64 位 IE,则需要确保该控件支持 64 位。
回答by Lightness Races in Orbit
There is no document.OurActiveX
, because the name
attribute in your HTML is broken (you've used a "smart quotes" in place of a normal double quote — if you look carefully, the syntax highlighting gives this away).
没有document.OurActiveX
,因为name
您的 HTML 中的属性已损坏(您使用了“智能引号”代替了普通的双引号——如果仔细观察,语法高亮显示了这一点)。
So, in fact, document.OurActiveX
is undefined
, and that's why you can't invoke any methods on it.
所以,事实上,document.OurActiveX
is undefined
,这就是为什么你不能在它上面调用任何方法。
<OBJECT id="OurActiveX" name=”OurActiveX" classid="..."></OBJECT>
Becomes:
变成:
<OBJECT id="OurActiveX" name="OurActiveX" classid="..."></OBJECT>
Anyway, selecting DOM nodes like document.someName
is highly antiquated and a little error-prone; get rid of the name
attribute entirely and use document.getElementById
to select the node, like you have elsewhere.
无论如何,选择像这样的 DOM 节点document.someName
是非常过时的并且有点容易出错;name
完全摆脱该属性并用于document.getElementById
选择节点,就像您在其他地方一样。
回答by dcinadr
ActiveX doesn't work with 64bit IE.
ActiveX 不适用于 64 位 IE。