一、ActiveX控件的检测、安装与卸载
( 1 ) 用JavaScript检测系统中是否已经安装了某个ActiveX控件
try {
var ax = new ActiveXObject(“控件名称”);
alert(“已安装”);
} catch (e) {
alert(“未安装”);
}
如果组件不是自己编写的,要确定控件名称,首先要知道控件的CLSID。每个COM组件都会对应一个CLSID,可在IE管理加载项中获得其CLSID,然后在注册表的HKEY_CLASSESS_ROOT
中查找CLSID,打开它的节点,其中有一项是ProgID,它的值就是创建该控件时所需的名称。
Demo:
< html >
< head >
< title > 安装ActiveX < / title>
< / head>
< body >
< h1 id = " Tip " > 正在加载控件…… < / h1>
< object
classid = " CLSID:B2EC6023-6C00-49F9-A8BE-3AAC4E326BA4 "
codebase = " http://www.demo.com/bin/activex.cab#version=0,0,0,1 " style = " display:none " >< / object>
< / body>
< script type = " text/javascript " >
window.onload = function () {
try {
var ax = new ActiveXObject( " name " );
$( " Tip " ).innerHTML = ' 安装完成 ' ;
} catch (e) {
$( " Tip " ).innerHTML = ' 等待您的操作… '
+ ' <p>现在您的浏览器或安全防护软件可能阻止了控件的安装。<br> '
+ ' 请单击信息栏,然后选择"安装 ActiveX 控件"<br> '
+ ' 在”IE安全警告”对话框中,单击"安装"</p> ' ;
}
};
< / script>
< / html>
( 2 ) 如何卸载ActiveX控件
IE菜单栏-工具-管理加载项-工具栏和扩展-所有加载项,
双击某控件,复制文件路径,运行 " regsvr32 /u 文件路径 " 命令,卸载成功。
二、JavaScript检查ActiveX控件是否已经安装过,这一篇的检测控件是否安装过省去了设置ie安全级别的麻烦!
function detectPlugin(CLSID,functionName)
{
var pluginDiv = document.createElement( " <div id=\"pluginDiv\" style=\"display:none\"></div> " )
document.body.insertBefore(pluginDiv);
pluginDiv.innerHTML = ' <object id="objectForDetectPlugin" classid="CLSID: ' + CLSID + ' "></object> ' ;
try
{
if (eval( " objectForDetectPlugin. " + functionName) == undefined)
{
pluginDiv.removeNode( true ); // 删除pluginDiv及其所有的子元素
return false ;
}
else
{
pluginDiv.removeNode( true ); // 删除pluginDiv及其所有的子元素
return true ;
}
}
catch (e)
{
return false ;
}
}
这是通用的方法,只需要把唯一的Activex的clsid和任意一个属性或方法名传进来就可以判断了。(找了两个小时才找到 - _ -! )
下附测试代码:
<! DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN " " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
< html xmlns = " http://www.w3.org/1999/xhtml " >
< head >
< meta http - equiv = " Content-Type " content = " text/html; charset=gb2312 " / >
< title > ~~~~ < / title>
< / head>
< script language = " javascript " >
function openreg(){
if (detectPlugin( ' A0F5EA74-8C04-4AF7-B7EA-DCB43F53ED45 ' , ' CurVersion ' ) == false )
{
alert( " 控件未安装 " );
}
}
function detectPlugin(CLSID,functionName)
{
var pluginDiv = document.createElement( " <div id=\"pluginDiv\" style=\"display:none\"></div> " )
document.body.insertBefore(pluginDiv);
pluginDiv.innerHTML = ' <object id="objectForDetectPlugin" classid="CLSID: ' + CLSID + ' "></object> ' ;
try
{
if (eval( " objectForDetectPlugin. " + functionName) == undefined)
{
pluginDiv.removeNode( true ); // 删除pluginDiv及其所有的子元素
return false ;
}
else
{
pluginDiv.removeNode( true ); // 删除pluginDiv及其所有的子元素
return true ;
}
}
catch (e)
{
return false ;
}
}
< / script>
< body >
< p > 通过浏览器打开Topteam客户端 ---- 测试 < / p>
< p >
< input type = " button " value = " 进入系统 " onclick = " openreg(); "/ >
< / p>
< / body>
< / html>
三、JavaScript检查ActiveX控件是否已经安装过
有下列两种方式去检测是否安装,如果在本地iis运行,检测速度很快,放到远程后速度很慢,至少要两分钟
1 .采用object元素的object属性是否为空可以判断此控件是否存在,如
< object classid = " clsid:00460182-9E5E-11d5-B7C8-B8269041DD57 " id = " activeObj " width = " 100% " height = " 100% " >
< param name = " BorderStyle " value = " 1 " >
< / object>
< script >
if (document.all.activeObj.object == null ) {
< / script>
2 .通过检测对象的属性是否未定义检测
var mObject = false ;
try {
var mFieldList = mainForm.activeObj.FieldsList; //
} catch (e){mObject = true ;}
if ( ! mObject){...}
( 1 ) 用JavaScript检测系统中是否已经安装了某个ActiveX控件
try {
var ax = new ActiveXObject(“控件名称”);
alert(“已安装”);
} catch (e) {
alert(“未安装”);
}
如果组件不是自己编写的,要确定控件名称,首先要知道控件的CLSID。每个COM组件都会对应一个CLSID,可在IE管理加载项中获得其CLSID,然后在注册表的HKEY_CLASSESS_ROOT
中查找CLSID,打开它的节点,其中有一项是ProgID,它的值就是创建该控件时所需的名称。
Demo:
< html >
< head >
< title > 安装ActiveX < / title>
< / head>
< body >
< h1 id = " Tip " > 正在加载控件…… < / h1>
< object
classid = " CLSID:B2EC6023-6C00-49F9-A8BE-3AAC4E326BA4 "
codebase = " http://www.demo.com/bin/activex.cab#version=0,0,0,1 " style = " display:none " >< / object>
< / body>
< script type = " text/javascript " >
window.onload = function () {
try {
var ax = new ActiveXObject( " name " );
$( " Tip " ).innerHTML = ' 安装完成 ' ;
} catch (e) {
$( " Tip " ).innerHTML = ' 等待您的操作… '
+ ' <p>现在您的浏览器或安全防护软件可能阻止了控件的安装。<br> '
+ ' 请单击信息栏,然后选择"安装 ActiveX 控件"<br> '
+ ' 在”IE安全警告”对话框中,单击"安装"</p> ' ;
}
};
< / script>
< / html>
( 2 ) 如何卸载ActiveX控件
IE菜单栏-工具-管理加载项-工具栏和扩展-所有加载项,
双击某控件,复制文件路径,运行 " regsvr32 /u 文件路径 " 命令,卸载成功。
二、JavaScript检查ActiveX控件是否已经安装过,这一篇的检测控件是否安装过省去了设置ie安全级别的麻烦!
function detectPlugin(CLSID,functionName)
{
var pluginDiv = document.createElement( " <div id=\"pluginDiv\" style=\"display:none\"></div> " )
document.body.insertBefore(pluginDiv);
pluginDiv.innerHTML = ' <object id="objectForDetectPlugin" classid="CLSID: ' + CLSID + ' "></object> ' ;
try
{
if (eval( " objectForDetectPlugin. " + functionName) == undefined)
{
pluginDiv.removeNode( true ); // 删除pluginDiv及其所有的子元素
return false ;
}
else
{
pluginDiv.removeNode( true ); // 删除pluginDiv及其所有的子元素
return true ;
}
}
catch (e)
{
return false ;
}
}
这是通用的方法,只需要把唯一的Activex的clsid和任意一个属性或方法名传进来就可以判断了。(找了两个小时才找到 - _ -! )
下附测试代码:
<! DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN " " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
< html xmlns = " http://www.w3.org/1999/xhtml " >
< head >
< meta http - equiv = " Content-Type " content = " text/html; charset=gb2312 " / >
< title > ~~~~ < / title>
< / head>
< script language = " javascript " >
function openreg(){
if (detectPlugin( ' A0F5EA74-8C04-4AF7-B7EA-DCB43F53ED45 ' , ' CurVersion ' ) == false )
{
alert( " 控件未安装 " );
}
}
function detectPlugin(CLSID,functionName)
{
var pluginDiv = document.createElement( " <div id=\"pluginDiv\" style=\"display:none\"></div> " )
document.body.insertBefore(pluginDiv);
pluginDiv.innerHTML = ' <object id="objectForDetectPlugin" classid="CLSID: ' + CLSID + ' "></object> ' ;
try
{
if (eval( " objectForDetectPlugin. " + functionName) == undefined)
{
pluginDiv.removeNode( true ); // 删除pluginDiv及其所有的子元素
return false ;
}
else
{
pluginDiv.removeNode( true ); // 删除pluginDiv及其所有的子元素
return true ;
}
}
catch (e)
{
return false ;
}
}
< / script>
< body >
< p > 通过浏览器打开Topteam客户端 ---- 测试 < / p>
< p >
< input type = " button " value = " 进入系统 " onclick = " openreg(); "/ >
< / p>
< / body>
< / html>
三、JavaScript检查ActiveX控件是否已经安装过
有下列两种方式去检测是否安装,如果在本地iis运行,检测速度很快,放到远程后速度很慢,至少要两分钟
1 .采用object元素的object属性是否为空可以判断此控件是否存在,如
< object classid = " clsid:00460182-9E5E-11d5-B7C8-B8269041DD57 " id = " activeObj " width = " 100% " height = " 100% " >
< param name = " BorderStyle " value = " 1 " >
< / object>
< script >
if (document.all.activeObj.object == null ) {
< / script>
2 .通过检测对象的属性是否未定义检测
var mObject = false ;
try {
var mFieldList = mainForm.activeObj.FieldsList; //
} catch (e){mObject = true ;}
if ( ! mObject){...}