-
-
Save tanepiper/1935828 to your computer and use it in GitHub Desktop.
javascript: hackery in jsdom
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var jsdom = require('jsdom'); | |
| window.log = console.log; | |
| var window = jsdom.jsdom('<a href="javascript:log(\'clicked!\');">click me</a>').createWindow(); | |
| var a = window.document.getElementsByTagName('a')[0]; | |
| a.addEventListener('click', function(e) { | |
| if (e.target.href.substring(0,10) === "javascript") { | |
| window.run(e.target.href.substring(11), 'click-handler'); | |
| } | |
| }); | |
| var e = window.document.createEvent('MouseEvent'); | |
| e.initEvent('click', true, true); | |
| a.dispatchEvent(e); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment