none
Calling ActiveX function from Javascript

    Question

  • Hi,

    From what I've heard, you're supposed to be able to call an embedded activex function or set one of its properties from the javascript in an html/asp page as long as the function or property is declared as public in the code.

    I have an activex control embedded in an html page with the object tag:

    <object ID="gis" classid="clsid:C9905EA4-468A-46c0-BCF4-49A547B3A2E6">

    Then I try to call a public function of the control like this:

    <script>

    function showbox()
    {
       gis.ShowMBox();
    }

    <script>

    All the function does is show a messagebox.

    I have an html button that calls the javascript function like this:

    <input type=button value="SetDoc" onclick="showbox()">

    When I click the button which calls the javascript function, which in turn calls the activex function, I get a page error icon in the status bar, and when I double click it here's the error message I see:

    Line: 12

    Char: 2

    Error: Object doesn't support this property or method.

    Code: 0

    What's wrong with what I'm trying to do.  Has anyone tried to do this and succeeded?

    Thanks

    Friday, January 05, 2007 8:24 PM

All replies

  • This is because your control is not marked as "safe for scripting". By default IE prevents interaction with unsafe controls.

    Temporarily you can change the security setting of your current zone to allow the access:

    Tools->Internet Options->Security->Custom Level...->ActiveX controls and plug-ins->Initialize and script ActiveX controls not marked as safe for scripting : Enabled. (WARNING!! You should only open this for temporary use and know exactly the control in your page is safe)

    A complete solution is implementing your control as safe. Here you can find the reference:

    http://msdn2.microsoft.com/en-us/library/aa751977.aspx

     

    Tuesday, January 09, 2007 8:09 AM
  • Hi,

    I tried Initialize and script ActiveX controls not marked as safe for scripting : Enabled.

    But it is of no use, i'm getting the same error object doesnot support property.

    Has anyone solved the issue??

     

    Thursday, February 01, 2007 7:04 AM
  • Hi,

    I could fix the issue by moving the ActiveX Control tag from <form> tag to <body>

    The Mark up that shown error was like this

    <body>

    <form id="form1" runat="server">  

    <object id="myActiveX" name="myActiveX" classid="myActiveX.dll#myActiveX.myActiveXUserControl">
     <param name="Param1" value= "
    value1" />  
     <param name="Param2" value= "42" /> </object>   
     

    <input type="button" id="btnUpload" onclick="button_Click()" Text="Call JS"/>

    </form>

     

    Check the following working code:

    <body>

    <object id="myActiveX" name="myActiveX" classid="myActiveX.dll#myActiveX.myActiveXUserControl">
     <param name="Param1" value= "
    value1" />  
     <param name="Param2" value= "42" /> </object>

    <form id="form1" runat="server">      

    <input type="button" id="btnUpload" onclick="button_Click()" Text="Call JS"/>

    </form>

     

    For Futher reading follow the links

    http://support.microsoft.com/kb/313891

    http://msdn.microsoft.com/msdnmag/issues/02/01/UserCtrl/

     

    Saturday, February 03, 2007 11:36 AM