Skip to content Skip to sidebar Skip to footer

Adding Keylistener And Using Javascript To Click A Link In Greasemonkey

I want to create a greasymonkey script, which will add a shortcut key for logout action in one mail site. Currently the logout link '?logout&hl=en' which have an id=':r5'. I am

Solution 1:

I do not think that you will be able to click a link from the script. You should try to redirect to the link location instead:

.....
e=document.getElementById(':r5'); 
document.location.href = e.href;
.....

Solution 2:

This is either a bug or a security "feature" of Mozilla browsers (developers haven't decided). See: "simulating a click on an anchor using dispatchEvent and initMouseEvent does not trigger a real click".

So you can't trigger a link that way (for now).

If it is an ordinary link use:

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

. If it is a JavaScript call, EG <a id=":r5" href="SomeFunc()">foo</a> use:

unsafeWindow.SomeFunc();

Post a Comment for "Adding Keylistener And Using Javascript To Click A Link In Greasemonkey"