[python-win32] Please help! How to get the event handler with IE Dom interfaces?

Xin Zhao uszhaoxin at gmail.com
Wed May 26 11:18:59 CEST 2010


Hey all,

I am using pywin32 code get all event handlers defined in a HTML page in IE.
 I used pythoncom to start IE, then get document, and finally reached
IHTMLElement object.  If the html page defines "onclick=xxx",
element.onclick returns the click handler. However, if an event handler is
defined in javascript, element.onclick simply returns NULL. What's the right
way to get the event handler then?

Note: I don't have to know detail about the event handler. It's good enough
to know that an event handler is associated with an element.

Thanks,
xin

Below is an example that uses javascript to define event handler.

<!doctype html>
<html>
  <head>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript"> </script>
  </head>
  <body>
    <script>
      $(document).ready(function(){
        $("a").click(function(event){
          $(this).hide("slow");
          alert("Thanks for visiting!");
          window.location="http://cnn.com";
        });
      });
    </script>
    <a>jQuery</a>
  </body>
</html>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20100526/6c64971e/attachment.html>


More information about the python-win32 mailing list