Handling ActiveX events in JavaScript (Internet Explorer)

Discussion in 'Javascript' started by klimontovich@gmail.com, Oct 24, 2005.

  1. Guest

    Hello!

    I'm trying to handle events raising by Microsoft ActiveX Spreadsheet
    control.
    I use following code to include this control into page:

    <object classid="clsid:0002E551-0000-0000-C000-000000000046"
    id="Spreadsheet1"">

    </object>

    Than i'm trying to handle onclick event by following code:

    Spreadsheet1.onclick = function() {
    alert(1);
    }

    This code has no effect -- no alert message, but no error message. But
    the following code:

    Spreadsheet1.click = function() {
    alert(1);
    }

    raises error "object doesn't support this action". This means, that
    onclick event is khown by javascript. But by using VBScript I can hanle
    onclick event,
    this code works right:

    Sub Spreadsheet1_click()
    alert Spreadsheet1.cells(5,4).value
    End Sub

    Does anybode have experience in catching activeX events by JS?
    , Oct 24, 2005
    #1
    1. Advertising

  2. Guest

    Sorry

    <SCRIPT FOR="Spreadsheet1" EVENT="click()" LANGUAGE="Jscript">
    alert(1);
    </SCRIPT>

    This code works as I wanted.
    , Oct 24, 2005
    #2
    1. Advertising

  3. RobG Guest

    wrote:
    > Sorry
    >
    > <SCRIPT FOR="Spreadsheet1" EVENT="click()" LANGUAGE="Jscript">
    > alert(1);
    > </SCRIPT>
    >
    > This code works as I wanted.


    Using a 'for' attribute on a script element to add it to an element is
    an 'IE-ism' that will only work in IE.

    Likely your page only works in IE anyway, but for the record some
    cross-browser ways of adding the onclick to the object element are to
    either add it inline, directly in the <object> HTML source tag:

    <object classid="clsid:0002E551-0000-0000-C000-000000000046"
    id="Spreadsheet1"
    onclick="alert(1)";
    >...</object>


    or add it dynamically after the object has been created:

    <object id="Spreadsheet1"...>...</object>

    <script type="text/javascript">
    var el;
    if (document.getElementById){
    el = document.getElementById('Spreadsheet1');
    } else if (document.all){
    el = document.all['Spreadsheet1'];
    }
    el.onclick = function(){alert(1);};
    </script>

    If you don't need to support old IE, document.all bit can be removed.
    Check out the group FAQ for various options:

    <URL:http://www.jibbering.com/faq/#FAQ4_15>




    --
    Rob
    RobG, Oct 24, 2005
    #3
  4. Randy Webb Guest

    RobG said the following on 10/24/2005 5:05 PM:
    > wrote:
    >
    >> Sorry
    >>
    >> <SCRIPT FOR="Spreadsheet1" EVENT="click()" LANGUAGE="Jscript">
    >> alert(1);
    >> </SCRIPT>
    >>
    >> This code works as I wanted.

    >
    >
    > Using a 'for' attribute on a script element to add it to an element is
    > an 'IE-ism' that will only work in IE.


    I doubt that an ActiveX Control controlling a Spreadsheet control will
    working anything *but* IE so using IE-only code is not a problem.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Randy Webb, Oct 24, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrice Vogel
    Replies:
    0
    Views:
    514
    Patrice Vogel
    Mar 7, 2005
  2. dlcf123
    Replies:
    0
    Views:
    326
    dlcf123
    Jun 1, 2006
  3. jojoba
    Replies:
    1
    Views:
    1,060
    David Pratt
    Mar 2, 2006
  4. Peter Wlodarczak
    Replies:
    1
    Views:
    463
    mlimber
    May 25, 2006
  5. Joe Attardi
    Replies:
    20
    Views:
    280
    Thomas 'PointedEars' Lahn
    Feb 3, 2006
Loading...

Share This Page