Handling ActiveX events in JavaScript (Internet Explorer)

K

klimontovich

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?
 
K

klimontovich

Sorry

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

This code works as I wanted.
 
R

RobG

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>
 
R

Randy Webb

RobG said the following on 10/24/2005 5:05 PM:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top