Handling ActiveX events in JavaScript (Internet Explorer)

  • Follow


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?

0
Reply klimontovich (3) 10/24/2005 6:06:39 PM

Sorry

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

This code works as I wanted.

0
Reply klimontovich 10/24/2005 6:13:46 PM


klimontovich@gmail.com 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
0
Reply RobG 10/24/2005 9:05:38 PM

RobG said the following on 10/24/2005 5:05 PM:
> klimontovich@gmail.com 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
0
Reply Randy 10/24/2005 9:36:58 PM

3 Replies
527 Views

(page loaded in 0.06 seconds)

Similiar Articles:











7/23/2012 12:42:34 AM


Reply: