自从
微软对IE6的ActiveX更新后,每次用IE打开带有ActiveX控件的页面时,必须要进行控件激活操作(点击相关控件),否则该控件将无法正常工作。如果在页面上使用ActiveX控件不多的话,每次多点一下也就算了,不过一旦要频繁操作或者控件很多,每次要做这个重复劳动时,客户肯定会疯掉了。
MSDN提供了相应的解决办法,可以不需要手工激活,回到以前一样的操作。下面三种办法,关键是把传统页面和控件输出进行分离,技术核心是DHTML和脚本。
方法一(入门篇,解决问题即可):
<!-- ActiveX.html -->
<html>
<body leftmargin=0 topmargin=0 scroll=no>
<script src="docwrite.js"></script>
</body>
</html>
// docwrite.js
document.write('<object classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6">');
document.write('<param name="URL" value="example.wmv">');
document.write('<param name="autoStart" value="-1"></object>');
方法二(专业篇):
<!-- ActiveX.html -->
<html>
<body>
<div id="DivID">
<script src="createElementExplicit.js"></script>
</body>
</html>
// createElementExplicit.js
var myObject = document.createElement('object');
DivID.appendChild(myObject);
myObject.width = "200";
myObject.height = "100";
myObject.classid= "clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6";
myObject.URL = "example.wmv";
myObject.uiMode = "none" ;
方法三(终极篇,适合批量更新):
<!-- ActiveX.html -->
<html>
<head>
<script src="external_script.js" language="JScript"></script>
</head>
<body>
<div id="EXAMPLE_DIV_ID">
This text will be replaced by the control
</div>
<script language="JScript">
CreateControl( "EXAMPLE_DIV_ID",
"clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6",
"EXAMPLE_OBJECT_ID", "600", "400", "example.wmv",
"-1")
</script>
</body>
</html>
// external_script.js
function CreateControl(DivID, CLSID, ObjectID,
WIDTH, HEIGHT, URL, AUTOSTART)
{
var d = document.getElementById(DivID);
d.innerHTML =
'<object classid=' + CLSID + ' id=' + ObjectID +
' width=' + WIDTH + ' height=' + HEIGHT +'>
<param name="URL" value=' + URL + '>
<param name="autoStart" value=' + AUTOSTART + '/>';
}
方法一(入门篇,解决问题即可):
<!-- ActiveX.html -->
<html>
<body leftmargin=0 topmargin=0 scroll=no>
<script src="docwrite.js"></script>
</body>
</html>
// docwrite.js
document.write('<object classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6">');
document.write('<param name="URL" value="example.wmv">');
document.write('<param name="autoStart" value="-1"></object>');
方法二(专业篇):
<!-- ActiveX.html -->
<html>
<body>
<div id="DivID">
<script src="createElementExplicit.js"></script>
</body>
</html>
// createElementExplicit.js
var myObject = document.createElement('object');
DivID.appendChild(myObject);
myObject.width = "200";
myObject.height = "100";
myObject.classid= "clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6";
myObject.URL = "example.wmv";
myObject.uiMode = "none" ;
方法三(终极篇,适合批量更新):
<!-- ActiveX.html -->
<html>
<head>
<script src="external_script.js" language="JScript"></script>
</head>
<body>
<div id="EXAMPLE_DIV_ID">
This text will be replaced by the control
</div>
<script language="JScript">
CreateControl( "EXAMPLE_DIV_ID",
"clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6",
"EXAMPLE_OBJECT_ID", "600", "400", "example.wmv",
"-1")
</script>
</body>
</html>
// external_script.js
function CreateControl(DivID, CLSID, ObjectID,
WIDTH, HEIGHT, URL, AUTOSTART)
{
var d = document.getElementById(DivID);
d.innerHTML =
'<object classid=' + CLSID + ' id=' + ObjectID +
' width=' + WIDTH + ' height=' + HEIGHT +'>
<param name="URL" value=' + URL + '>
<param name="autoStart" value=' + AUTOSTART + '/>';
}