在网页中如何用Javascript设置在VC环境下开发的ActiveX的属性或调用它自定义的方法。最好有详细的例子。

解决方案 »

  1.   

    <script language="javascript">
    var obj = new ActiveXObject( "YourCom.Class" );//ProgID
    obj.Property1 = 5;
    obj.Property2 = obj.Property1;
    obj.Method1( obj.Property1, obj.Property2 );
    </script>
      

  2.   


           <OBJECT id=oGrid codeBase=CAB/CabVSGrid7u.CAB height="100%" width="100%" 
          classid=clsid:D76D7126-4A96-11D3-BD95-D296DC2DD072 VIEWASTEXT>
    <PARAM NAME="_cx" VALUE="14208">
    <PARAM NAME="_cy" VALUE="9155">
    <PARAM NAME="_ConvInfo" VALUE="1">
    <PARAM NAME="Appearance" VALUE="1">
    <PARAM NAME="BorderStyle" VALUE="1">
    <PARAM NAME="Enabled" VALUE="-1">
    <PARAM NAME="Font" VALUE="Times New Roman">
    <PARAM NAME="MousePointer" VALUE="0">
    <PARAM NAME="BackColor" VALUE="-2147483643">
    <PARAM NAME="ForeColor" VALUE="-2147483640">
    <PARAM NAME="BackColorFixed" VALUE="-2147483633">
    <PARAM NAME="ForeColorFixed" VALUE="-2147483630">
    <PARAM NAME="BackColorSel" VALUE="-2147483635">
    <PARAM NAME="ForeColorSel" VALUE="-2147483634">
    <PARAM NAME="BackColorBkg" VALUE="-2147483636">
    <PARAM NAME="BackColorAlternate" VALUE="-2147483643">
    <PARAM NAME="GridColor" VALUE="-2147483633">
    <PARAM NAME="GridColorFixed" VALUE="-2147483632">
    <PARAM NAME="TreeColor" VALUE="-2147483632">
    <PARAM NAME="FloodColor" VALUE="192">
    <PARAM NAME="SheetBorder" VALUE="-2147483642">
    <PARAM NAME="FocusRect" VALUE="1">
    <PARAM NAME="HighLight" VALUE="1">
    <PARAM NAME="AllowSelection" VALUE="-1">
    <PARAM NAME="AllowBigSelection" VALUE="-1">
    <PARAM NAME="AllowUserResizing" VALUE="3">
    <PARAM NAME="SelectionMode" VALUE="0">
    <PARAM NAME="GridLines" VALUE="1">
    <PARAM NAME="GridLinesFixed" VALUE="2">
    <PARAM NAME="GridLineWidth" VALUE="1">
    <PARAM NAME="Rows" VALUE="1">
    <PARAM NAME="Cols" VALUE="10">
    <PARAM NAME="FixedRows" VALUE="1">
    <PARAM NAME="FixedCols" VALUE="1">
    <PARAM NAME="RowHeightMin" VALUE="0">
    <PARAM NAME="RowHeightMax" VALUE="0">
    <PARAM NAME="ColWidthMin" VALUE="0">
    <PARAM NAME="ColWidthMax" VALUE="0">
    <PARAM NAME="ExtendLastCol" VALUE="0">
    <PARAM NAME="FormatString" VALUE="">
    <PARAM NAME="ScrollTrack" VALUE="0">
    <PARAM NAME="ScrollBars" VALUE="3">
    <PARAM NAME="ScrollTips" VALUE="0">
    <PARAM NAME="MergeCells" VALUE="0">
    <PARAM NAME="MergeCompare" VALUE="0">
    <PARAM NAME="AutoResize" VALUE="-1">
    <PARAM NAME="AutoSizeMode" VALUE="0">
    <PARAM NAME="AutoSearch" VALUE="0">
    <PARAM NAME="AutoSearchDelay" VALUE="2">
    <PARAM NAME="MultiTotals" VALUE="-1">
    <PARAM NAME="SubtotalPosition" VALUE="1">
    <PARAM NAME="OutlineBar" VALUE="0">
    <PARAM NAME="OutlineCol" VALUE="0">
    <PARAM NAME="Ellipsis" VALUE="0">
    <PARAM NAME="ExplorerBar" VALUE="7">
    <PARAM NAME="PicturesOver" VALUE="0">
    <PARAM NAME="FillStyle" VALUE="0">
    <PARAM NAME="RightToLeft" VALUE="0">
    <PARAM NAME="PictureType" VALUE="0">
    <PARAM NAME="TabBehavior" VALUE="0">
    <PARAM NAME="OwnerDraw" VALUE="0">
    <PARAM NAME="Editable" VALUE="0">
    <PARAM NAME="ShowComboButton" VALUE="-1">
    <PARAM NAME="WordWrap" VALUE="0">
    <PARAM NAME="TextStyle" VALUE="0">
    <PARAM NAME="TextStyleFixed" VALUE="0">
    <PARAM NAME="OleDragMode" VALUE="0">
    <PARAM NAME="OleDropMode" VALUE="0">
    <PARAM NAME="ComboSearch" VALUE="3">
    <PARAM NAME="AutoSizeMouse" VALUE="-1">
    <PARAM NAME="FrozenRows" VALUE="0">
    <PARAM NAME="FrozenCols" VALUE="0">
    <PARAM NAME="AllowUserFreezing" VALUE="0">
    <PARAM NAME="BackColorFrozen" VALUE="0">
    <PARAM NAME="ForeColorFrozen" VALUE="0">
    <PARAM NAME="WallPaperAlignment" VALUE="9">
    </OBJECT><script>
    function init()
    {
    oGrid.Rows = 5;
    oGrid.Cols = 5;
    }
    </script>
      

  3.   

    方法有很多,下面是一个:
    先用object生成一个对像,在网页就可以通过它的名字在javascript中调用它的属性或方法了。<OBJECT  classid=clsid:E0A87E03-8CBA-44BE-B60B-A03BA274F6FB 
                                           codebase="http://wenn/soundrecord.ocx#version=1,0,0,5" 
                                  height=15 id=SoundRecord name=SoundRecord 
                                  style="HEIGHT: 15px; LEFT: 0px; TOP: 0px; WIDTH: 94px" 
                                  width=300 VIEWASTEXT><PARAM NAME="_ExtentX" VALUE="2487"><PARAM NAME="_ExtentY" VALUE="397"></OBJECT>
    function RecordStream()
    {
    var flag;
    flag = document.SoundRecord.WaveRecord();
    if (flag)
      Stateflag = 1;
    }
      
    function PlayStream()
    {
    var flag;
    flag = document.SoundRecord.WavePlay();
    if (flag)
      Stateflag = 2;
    }
    function StopStream()
    {
      if (Stateflag == 1)
        document.SoundRecord.WaveStopRecord();
      else if (Stateflag == 2)
        document.SoundRecord.WaveStopPlay();
    }
    function ClearStream()
    {
      //document.SoundRecord.SaveWavFile();
    }
    function SaveStream()
    {
      filename = document.SoundRecord.SaveWavFile();
      document.sm.attach1.value = filename;   
    }
      

  4.   

    When you include the <PARAM> tags as children of the <OBJECT> tags, Internet Explorer sends the data that you specify to the control when the control is first instantiated. For example, to specify an initial value for the Message property, you can insert a <PARAM> tag between the opening and closing object tags for the control. This HTML code looks like this:<OBJECT ID="AtlCtrl"
            CLASSID="CLSID:638B718E-AEF1-11D2-A9BA-444553540001">
            <PARAM NAME="Message" VALUE="Hello, There!">
    </OBJECT> 
      

  5.   

    <script language="jscript" FOR="myact" event="OnGetMessage()" src="onmessage.js">
    </script>
    其中myact为activex的id,OnGetMessage()为activex的事件
    如果有此事件,则执行onmessage.js中的脚本
      

  6.   

    属性更简单:如有一个属性为connpara,则可以在脚本中写:
     myact.connpara = "1," + document.all.userid.value + "," + document.all.password.value;
      

  7.   

    方法的调用与属性一样,简单:如在某个按钮中执行方法test():
     myact.test();
      

  8.   

    <script language="javascript">
    var obj = new ActiveXObject( "YourCom.Class" );//ProgID
    obj.Property1 = 5;
    obj.Property2 = obj.Property1;
    obj.Method1( obj.Property1, obj.Property2 );
    </script>
    <OBJECT ID="AtlCtrl"
            CLASSID="CLSID:638B718E-AEF1-11D2-A9BA-444553540001">
            <PARAM NAME="Message" VALUE="Hello, There!">
    </OBJECT>
    <script language="jscript" FOR="AtlCtrl" event="OnGetMessage()" src="onmessage.js">
    </script>
    其中myact为activex的id,OnGetMessage()为activex的事件
    如果有此事件,则执行onmessage.js中的脚本
      

  9.   

    用HTML就可以了,如果你是想问如何用VC做的话,参看:
    http://expert.csdn.net/Expert/topic/1826/1826119.xml?temp=.3750421