Skip to content

Instantly share code, notes, and snippets.

@tmpvar
Created February 28, 2012 22:06
Show Gist options
  • Select an option

  • Save tmpvar/1935579 to your computer and use it in GitHub Desktop.

Select an option

Save tmpvar/1935579 to your computer and use it in GitHub Desktop.
javascript: hackery in jsdom
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);
@logankeenan
Copy link

Thanks this helped me out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment