Invoking JavaScript event handler in Internet Explorer by python/win32com

Florian Fredegar Haftmann fredegar at haftmann-online.de
Mon Mar 3 12:49:42 CET 2003


Hi!

I have the following problem:
I'm programming a python programme which controls Internet Explorer
via ActiveX/COM. When a document is read, an event handler is
associated with each button; each time the button is clicked, a
certain action is performed.
Since there could also be a "native" JavaScript event handler, it is
disabled.
When my own handler is finished, he is supposed to call the old
"native" handler. But how is that to be done?

If the old event handler is stored in self.oldevt, a call
self.oldevt()
only returns a textual representation; i've tried also calls like
.Fire() and .Invoke(), but self.oldevt does'nt have such attributes.

Makepy does not work on self.oldevt.

Of course you could use the .click method, but since I'd like to do
the same procedure with other event handlers, too, that is'nt useful.

Any hints how to call the JavaScript event handler from python?

Code fragment:

[...]

class ButtonHandler(html.HTMLButtonElementEvents):

    def __init__(self, button, oldevt = None):

        self.button = button
        self.oldevt = oldevt
        html.HTMLButtonElementEvents.__init__(self, button)

    def Ononclick(self):

        [... any action ...]
        if self.oldevt:
            self.oldevt() <----------------------- ?????????????????

tagset = doc.getElementsByTagName('input')
for idx in xrange(tagset.length):
    tag = tagset(idx)
    if tag.type.lower() in ('submit', 'button', 'reset'):
        oldevt = getattr(tag, 'onclick', None)
        bhandler = ButtonHandler(tag, oldevt)
        if oldevt:
            tag.onclick = u""


Thanks for any remarks
Florian




More information about the Python-list mailing list