大家可以看到在下载ACTIVEX控件时IE通常会弹出一个对话框问是否容许下载并执行该ACTIVEX控件,如果用户点否则控件无法下载,那我后面JS对控件方法的调用肯定会出错,如何避免这个问题呢?是否可以在调用方法之前用JS判断一下呢?请看我下面的讲解?
方法一:
你可以试着调用ActiveX control里的一个方法Method, 如调用不成功,则说明control还没有下载成功.例如:
<script language="javascript">
var bControlLoaded=false;
function window.onload()
{
try
{
if (objectID.someMethod)
bControlLoaded = true;
}
catch (ex)
{}
alert(bControlLoaded);
}
</script>
<object id="objectID"></object>
换句话说,在你调用方法这前,检查bControlLoaded是否返回真.若不是,则报警,也可以转到用户定义的网页显示control没有下载成功.
<script language="javascript">
function window.onload()
{
try
{
if (objectID.someMethod)
bControlLoaded = true;
}
catch (ex)
{
alert("you did not install the control properly!");
window.location.href="someotherpage.html";
}
}
</script>
方法二:
<html XMLNS:CC>
<head>
<STYLE>
@media all { CC\:clientCaps {behavior:url(#default#clientCaps)}}
</Style>
<title>Client Capabilities</title>
</head>
<body onload="showComponentStatus();" bgcolor="#FFFFFF">
<CC:clientCaps id=clientCaps />
</body>
<script language=javascript>
function showComponentStatus(){
displayComponent("Address Book",
"{7790769C-0471-11D2-AF11-00C04FA35D02}");
displayComponent("DirectAnimation",
"{283807B5-2C60-11D0-A31D-00AA00B92C03}");
displayComponent("DirectAnimation Java Classes",
"{4F216970-C90C-11D1-B5C7-0000F8051515}");
displayComponent("DirectShow", "{44BBA848-CC51-11CF-AAFA-00AA00B6015C}");
displayComponent("Dynamic HTML Data Binding",
"{9381D8F2-0288-11D0-9501-00AA00B911A5}");
displayComponent("Dynamic HTML Data Binding for Java",
"{4F216970-C90C-11D1-B5C7-0000F8051515}");
displayComponent("Internet Connection Wizard",
"{5A8D6EE0-3E18-11D0-821E-444553540000}");
displayComponent("Internet Explorer 5 Web Browser",
"{89820200-ECBD-11CF-8B85-00AA005B4383}");
displayComponent("Internet Explorer Classes for Java",
"{08B0E5C0-4FCB-11CF-AAA5-00401C608555}");
displayComponent("Internet Explorer Help",
"{45EA75A0-A269-11D1-B5BF-0000F8051515}");
displayComponent("Internet Explorer Help Engine",
"{DE5AED00-A4BF-11D1-9948-00C04F98BBC9}");
displayComponent("Windows Media Player",
"{22D6F312-B0F6-11D0-94AB-0080C74C7E95}");
displayComponent("NetMeeting NT",
"{44BBA842-CC51-11CF-AAFA-00AA00B6015B}");
displayComponent("Offline Browsing Pack",
"{3AF36230-A269-11D1-B5BF-0000F8051515}");
displayComponent("Outlook Express",
"{44BBA840-CC51-11CF-AAFA-00AA00B6015C}");
displayComponent("Task Scheduler",
"{CC2A9BA0-3BDD-11D0-821E-444553540000}");
displayComponent("Microsoft virtual machine",
"{08B0E5C0-4FCB-11CF-AAA5-00401C608500}");
displayComponent("VRML 2.0 Viewer",
"{90A7533D-88FE-11D0-9DBE-0000C0411FC3}");
displayComponent("Wallet",
"{1CDEE860-E95B-11CF-B1B0-00AA00BBAD66}");
}
function displayComponent(compDesc, compID){
if (clientCaps.isComponentInstalled(compID, "componentID")){
alert("Installed.");
}
}
</script>
</html>