Using this html file: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"" http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Sample</title> <script type="text/javascript"> function doSomething(e) { alert('inside preexisting hanlder'); alert((window.event ? '' : 'not ') + 'found : window.event'); alert((e ? '' : 'not ') + 'found : window.event'); } </script> </head> <body> <div> <button id="one">One</button> <button id="two">Two</button> </div> </body> </html>
and this ruby code: ------------------------------------ require 'watir' include Watir module Watir class IE def run_script(js) ie.document.parentWindow.execScript(js) end end end ie = IE::start('c:/test.html') ie.button(:id, 'one').click #does nothing - no handler ie.run_script("document.getElementById('one').onclick=doSomething") p 'clicking one' ie.button(:id, 'one').click #shows doSomething handler ie.run_script("var func = function() {" + "alert(window.event ? 'found' : 'not found');" "if (window.event) alert(window.event.altKey);"+ "};" + "document.getElementById('two').onclick=func"); p 'clicking two' ie.button(:id, 'two').click #shows injected handler #press two manually here with alt held down to see event info ----------------------- See what you get. You mentioned IE, so I tried it on IE 6 (the only IE I have laying around). There are a lot of ways to attach event handlers in javascript and I'm not a javascript wizard by any means so I'm sure there are better ways. Hope it helps. -andy On Thu, Mar 12, 2009 at 2:54 PM, <andrew.d...@lthree.com> wrote: > > Yea, I've tried passing it as a parm with no luck also. Everything > says it is supposed to work, but I can't get it. > > > -~----------~----~----~----~------~----~------~--~--- > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Watir General" group. To post to this group, send email to watir-general@googlegroups.com Before posting, please read the following guidelines: http://wiki.openqa.org/display/WTR/Support To unsubscribe from this group, send email to watir-general-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/watir-general -~----------~----~----~----~------~----~------~--~---