最近一个项目的菜单采用Flash来做,可是新的浏览器上老是要点击一下激活后才可使用,查了相关资料才知道原来可以通过从外部文件加载控件的方法来实现不应激活即可使用。
1、document.write动态加载控件:
<!-- 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>');
2、修改元素的 outerHTML 属性
<!-- HTML 文件 -->
<html>
<body>
<div id="embedControlLocation">
<script src="embedControlOuterHTML.js"></script>
</div>
</body>
</html>
// outerhtml.js
embedControlLocation.outerHTML = '<embed src="examplecontrol">';
3、使用 document.createElement 加载使用 OBJECT 元素的 ActiveX 控件
<!-- HTML 文件 -->
<html>
<body>
<div id="DivID">
<script src="createElementExplicit.js"></script>
</div>
</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" ;
3、使用 innerHTML 和 JScript 函数加载 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 + '/>';
}
以上摘抄自 http://www.microsoft.com/china/MSDN/library/NetComm/activating_activex.mspx?mfr=true