自动激活activex control

微软调整了浏览器activex的策略,在被激活之前不能对他进行操作,没有激活时许多事件被屏蔽

被屏蔽事件如下

onactivate ondragleave onmouseout
onbeforeactivate ondragover onmouseover
onbeforecopy ondragstart onmouseup
onbeforecut ondrop onmousewheel
onbeforedeactivate onfocus onmove
onbeforepaste onfocusin onmoveend
onblur onfocusout onmovestart
onclick onhelp onpage
oncontextmenu onkeydown onpaste
oncontrolselect onkeypress onresize
oncopy onkeyup onresizeend
oncut onlosecapture onresizestart
ondblclick onmousedown onscroll
ondeactivate onmouseenter onselectstart
ondragend onmouseleave
ondragenter onmousemove

解决办法有下面几种(主要是由外部js文件动态载入控件以避免激活)

1.用document.write动态载入(注意不能使用writeln,如果使用writeln将会和直接载入一样要激活)

<!-- HTML File -->
<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 File -->
<html>
  <body> 
    <div id="embedControlLocation">
      <script src="embedControlOuterHTML.js"></script>
    </div>
  </body>
</html>
// outerhtml.js
embedControlLocation.outerHTML = '<embed src="examplecontrol">';

3.用createElement

<!-- HTML File -->
<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" ;

4.innerHtml

<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://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/overview/activating_activex.asp

codeproject上有人已经包装了现成的服务器控件用来做这件事情
http://www.codeproject.com/aspnet/AutoActivateControl.asp

你可能感兴趣的:(html,浏览器,Microsoft,asp)