<html>
<body>
</body>
<html>
<script language="javascript">
function test()
{
  var obj = document.createElement('object');
  obj.codebase = "http://127.0.0.1/cab/OcxSetup.cab";
  obj.classid ="clsid:FF987FC7-FEED-469C-89B0-0ACDA41401FE";
  obj.width = 300;
  obj.height = 300;  
  document.body.appendChild(obj);
}
test();
</script>如上,为什么当指定的ActiveX未安装时不会自动下载cab并安装.换成下面的代码可以自动注册插件,但因项目要求只能用上面的方式实现,请问高手如何解决?
<OBJECT id=test 
        classid=clsid:FF987FC7-FEED-469C-89B0-0ACDA41401FE
        codebase="http://127.0.0.1/cab/OcxSetup.cab"
        width="300"
        height="300">
</OBJECT>

解决方案 »

  1.   

    document.body.appendChild(obj);//是向节点的子节点列表的末尾添加新的子节点
    test();//不能放在这里执行
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title></title>
    <script language="javascript">
    function test()
    {
      var obj = document.createElement('object');
      obj.codebase = "http://127.0.0.1/cab/OcxSetup.cab";
      obj.classid ="clsid:FF987FC7-FEED-469C-89B0-0ACDA41401FE";
      obj.width = 300;
      obj.height = 300;   
      document.body.appendChild(obj);
    }
    </script>
    </head>
    <body>
    <script language="javascript">
    test();
    </script>
    </body>
    </html>
      

  2.   


    <html>
    <body>
    </body>
    <html>
    <script language="javascript">
    function test()
    {
      var obj = document.createElement("<object codebase='http://127.0.0.1/cab/OcxSetup.cab'>");
      obj.classid = "clsid:FF987FC7-FEED-469C-89B0-0ACDA41401FE";
      obj.width = 300;
      obj.height = 300;   
      document.body.appendChild(obj);
    }
     test();
    </script>
      

  3.   

     obj.classid ="clsid:FF987FC7-FEED-469C-89B0-0ACDA41401FE";改为
     obj.classid ="FF987FC7-FEED-469C-89B0-0ACDA41401FE";
      

  4.   

    这样试试<html>
    <body>
    </body>
    <html>
    <script language="javascript">
    function test()
    {
      var obj = document.createElement('div');
     obj.innerHTML="<OBJECT id=test classid=clsid:FF987FC7-FEED-469C-89B0-0ACDA41401FE codebase="http://127.0.0.1/cab/OcxSetup.cab" width="300" height="300">
    </OBJECT>";
      document.body.appendChild(obj);
    }
    test();
    </script>
      

  5.   

    obj.innerHTML='<OBJECT id=test classid=clsid:FF987FC7-FEED-469C-89B0-0ACDA41401FE codebase="http://127.0.0.1/cab/OcxSetup.cab" width="300" height="300">
    </OBJECT>';