469,579 Members | 1,102 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

Handling ActiveX events in JavaScript (Internet Explorer)

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 '05 #1
3 18737
Sorry

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

This code works as I wanted.

Oct 24 '05 #2
kl**********@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
Oct 24 '05 #3
RobG said the following on 10/24/2005 5:05 PM:
kl**********@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
Oct 24 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by wang xiaoyu | last post: by
reply views Thread by Jeff M | last post: by
2 posts views Thread by Fie Fie Niles | last post: by
4 posts views Thread by joebob | last post: by
12 posts views Thread by A.M. | last post: by
8 posts views Thread by Klaus Jensen | last post: by
1 post views Thread by Apu Nahasapeemapetilon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.