Javascript 如何检测客户端浏览器中是否启用了 ActiveX?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4313438/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 11:51:07  来源:igfitidea点击:

How do I detect if ActiveX is enabled in the browser of client?

javascriptactivex

提问by Philip

How do I detect if ActiveX is enabled in the browser of client?

如何检测客户端浏览器中是否启用了 ActiveX?

I tried following code, but it's not working in Firefox.

我尝试了以下代码,但它在 Firefox 中不起作用。

window.ActiveXObject not working in Firefox

any ideas?

有任何想法吗?

check the example here: http://jsfiddle.net/qXSvQ/2/

检查这里的例子:http: //jsfiddle.net/qXSvQ/2/

I get falsewhen I run this example.

false当我运行这个例子时,我得到了。

回答by Philip

ActiveX objects do not exist in anything but Internet Explorer. If you're trying to use them for XMLHTTPRequests, use the XMLHTTPRequest() object instead, using feature detection.

ActiveX 对象不存在于 Internet Explorer 中。如果您尝试将它们用于 XMLHTTPRequests,请改用 XMLHTTPRequest() 对象,使用特征检测。

if ("ActiveXObject" in window) { /* Do ActiveX Stuff */ }
else { /* ActiveX doesnt exist, use something else */ }

回答by mpdonadio

What isn't working? Is that throwing an error in FF? How about

什么不起作用?这是在 FF 中引发错误吗?怎么样

var hasAX = "ActiveXObject" in window;

回答by Chinmayee G

Below code should work, It is working on IE6 & FF 3.6.12 atleast.

下面的代码应该可以工作,它至少在 IE6 和 FF 3.6.12 上工作。

if(typeof(window.ActiveXObject)=="undefined"){
    alert("ActiveX Object not supported");
}else {
    alert("ActiveX Object  supported");
}