How can I assign event handlers externaly?

G

glevik

Hello,

I have written a script that gets trigered by IE's toolbar button. In
this script I would like to asign an event handler to an element of the
document currently open in IE. The way one access the document object
from a toolbar button script is:

var doc = external.menuArguments.document;

Now assuming the document has an element called TextArea1, the logical
thing to do would be:

parentwin.document.all('TextArea1').onkeypress = new
Function('window.alert(\'asdf\');');

Which goes compiles and runs, except the event handler does not get
triggered.

Another trick i tried is as follows:

var s = parentwin.document.createElement('script');
s.text = 'window.alert(\'asdf\')';
s.htmlFor = 'TextArea1';
s.event = 'onclick';
parentwin.document.scripts[0] = s;

Same result.

I would appreciate any suggestions you might have.

Lev
 
D

Dietmar Meier

var doc = external.menuArguments.document; ~~~
Now assuming the document has an element called TextArea1, the logical
thing to do would be:

parentwin.document.all('TextArea1').onkeypress = new
~~~~~~~~~~~~~~~~~~
Shouldn't that be "doc"?
Function('window.alert(\'asdf\');');

I would try it this way (untested quickhack):

var myWindow, myDocument, myElement;
if ((myWindow = external.menuArguments)
&& (myDocument = myWindow.document)
&& (myElement = myDocument.all('TextArea1'))
) {
myElement.onkeypress = function() {
myWindow.alert('asdf');
};
}

ciao, dhgm
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top