Adding keylistener and using javascript to click a link in Greasemonkey -


I want to create a sleek monkey script, which will add a shortcut key for logout action in a mail site.

The logout link "? Logout & amp; HL = N" currently contains id = ": r5" I get the node for the link I am capable of, but I am not able to click on it.

I tried the script as the following

  function key_event (event) {GM_log ("Hello"); GM_log (event.keyCode); //if(event.keyCode! = 112) Return; E = document.getElementById (': R5'); If (! E) {return;} var evObj = document.createEvent ('MouseEvents'); EvObj.initMouseEvent (('click'), true, true, window, 0,0,0,0,0, false false, false, false, 0, faucet); GM_log (E); E.dispatchEvent (evObj); } Document.addEventListener ("keypress", key_events, true);  


but it is not working Do you think that's wrong here?

Thanks

This is either a bug or security of the Mozilla browser " Feature "(developers have not decided). See:.

So you can not trigger a link like this (for now).

If this is the use of a common link:

  var sTargetURL = document.getElementById (': r5'). Href; Window.location.href = sTargetURL;  

.
If this is a Javascript call, then EG & lt; An id = ": r5" href = "somefunc ()" & gt; Foo & lt; / A & gt; Usage:

  Unsecured Window.SomeFunc ();  

Comments