• js创建调用ocx对象的几种方法,检测ocx是否可用


    1:创建ActiveX对象
       在web中使用ActiveX组件有两种方法,一是如下
    <HTML>
    <HEAD>
    <TITLE>rep_print_medcan.CAB</TITLE>
    </HEAD>
    <BODY>
    <OBJECT ID="Rep_Print_MedCan21"
    CLASSID="CLSID:C0558D51-6AFD-11D5-BF5C-005070024001"
    CODEBASE="rep_print_medcan.CAB#version=1,0,0,25">
    </OBJECT>
    </BODY>
    </HTML>
    OBJECT标签中,通过ID指点了对象的ID号,javascript可以使用该ID号来引用该对象,而classid用于标识这个组件,每个ActiveX组件都有唯一一个用于表示他的ID号。而codebase指定的程序下载到本地(在系统目录的“Downloaded Program Files”子目录下),然后调用组件程序的自注册入口函数注册到当前系统中,以后的创建都在本地进行,不再涉及codebase属性
     使用以上的方法来创建ActiveX对象,有些参数设置需要手抖的填写,麻烦,

    2、另外可以使用javascript的ActiveXObject对象来创建,一般过程是var act=new ActiveXObject(proid),proid为该ActiveX的标识号,是Classid的另一种表示方法

    其中proid指在ocxctrl.cpp文件下的:

    // 初始化类工厂和 guid

    IMPLEMENT_OLECREATE_EX(CtestOCX2Ctrl, "TESTOCX2.testOCX2Ctrl.1",
     0xe0d5a597, 0x336b, 0x4829, 0x84, 0xe0, 0x77, 0x43, 0x91, 0xc8, 0xe8, 0xdb)

    红色表示部分。

    3、

             var _tempPlayer = null;
             _tempPlayer = window.document.createElement("object");
             _tempPlayer.classid = "clsid:358DE739-F39F-4832-9458-80FDE806F845";
             _tempPlayer.id = "realtime_player"+i; // 唯一标识
             _tempPlayer.using = false; // 是否正在使用
             _tempPlayer.style.width = "100%";
             _tempPlayer.style.height = "100%";           

    或者:
                /*var _tempPlayer = window.document.createElement("object");
                _tempPlayer.setAttribute("id","realtime_player"+i);
                _tempPlayer.setAttribute("classid","clsid:358DE739-F39F-4832-9458-80FDE806F845");
                _tempPlayer.setAttribute("width","100%");
                _tempPlayer.setAttribute("height","100%");
                _tempPlayer.using = false;  //>是否正在使用 

    4、检测ocx是否可用的方法

    在js下是 var o = new ActiveXObject(ProgID);
    IE下若ocx存在是object,否则是null
    即:

    var o = new ActiveXObject(ProgID);
    if(o)

    {

    //存在

    }

    else

    {

    //不存在

    }


     

    <HTML>
    <HEAD>
    <TITLE>New Page</TITLE>
    
    <script language="javascript" type="text/javascript">
        //var a1 = new ActiveXObject("TESTOCX1.testOCX1Ctrl.1");
        var ocx;
        function createOcx() {
            ocx = document.createElement("object");
            ocx.setAttribute("id", "ocx1");
            ocx.setAttribute("height", 100);
            ocx.setAttribute("width", 51);
            ocx.setAttribute("classid", "clsid:DA44C63F-4844-483F-9DA0-7129E1A7F05B");
        }
    
        function DestoryOcx() {
             delete ocx;
        }
    
        function AddToDiv() {
            var div = document.getElementById("divOcxContainer");
            div.appendChild(ocx);
    
            ocx.Method2();
        }
    
        function RemoveFromDiv() {
            var div = document.getElementById("divOcxContainer");
            var ocx1 = document.getElementById("ocx1");
            div.removeChild(ocx1); 
        }
    
        window.onload = function() {
    
        }
    
    
        window.onunload = function() {
    
        }
    
    </script>
    
    </HEAD>
    <BODY>
    <div id="divOcxContainer">
    </div>
    <input type="button" id="btn1" name="btn1" value="创建ocx" title="创建ocx" onclick="createOcx()"></input>
    <input type="button" id="btn2" name="btn2" value="销毁ocx"  title="销毁ocx" onclick="DestoryOcx()"></input>
    <input type="button" id="Button1" name="btn2" value="添加到div"  title="添加到div" onclick="AddToDiv()"></input>
    <input type="button" id="Button2" name="btn2" value="从div移除"  title="从div移除" onclick="RemoveFromDiv()"></input>
    <OBJECT ID="testOCX1" WIDTH=100 HEIGHT=51
     CLASSID="CLSID:DA44C63F-4844-483F-9DA0-7129E1A7F05B">
        <PARAM NAME="_Version" VALUE="65536">
        <PARAM NAME="_ExtentX" VALUE="2646">
        <PARAM NAME="_ExtentY" VALUE="1323">
        <PARAM NAME="_StockProps" VALUE="0">
    </OBJECT>
    
    <OBJECT ID="testOCX2" WIDTH=100 HEIGHT=51
     CLASSID="CLSID:DA44C63F-4844-483F-9DA0-7129E1A7F05B">
        <PARAM NAME="_Version" VALUE="65536">
        <PARAM NAME="_ExtentX" VALUE="2646">
        <PARAM NAME="_ExtentY" VALUE="1323">
        <PARAM NAME="_StockProps" VALUE="0">
    </OBJECT>
    
    </BODY>
    </HTML>

    参考html文件代码:https://files.cnblogs.com/lidabo/Page1.rar

  • 相关阅读:
    Web进程被kill掉后线程还在运行怎么办?
    Spring Boot学习(二):配置文件
    POI实现excel的数据验证
    Spring Boot学习(一):入门篇
    lombok学习
    Java设计模式:单例模式
    关于org.springframework.web.filter.CharacterEncodingFilter的学习
    毕业三年,拿了北京户口,从年薪20W到年薪40W,说一点对后人有用的经验
    北漂去帝都大医院求医到底有多难?我的真实经历,真的是一路坎坷与辛酸~
    阿里面试官让我讲讲Unicode,我讲了3秒说没了,面试官说你可真菜
  • 原文地址:https://www.cnblogs.com/lidabo/p/2755448.html
Copyright © 2020-2023  润新知