可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have used following commands in my browser.xul to set a shortcut for my addon.
<keyset id="mainKeyset"> <key id="key_convert" modifiers="accel" keycode="VK_F12" oncommand="myfunction()" />" </keyset>
It used to work for previous versions of Firefox, but not anymore for newer versions. has anything changed in the syntax?
Thanks
回答1:
That code example looks correct, I suspect that there is some code within myfunction()
that is failing, so we need more information probably. Try to replace myfunction()
with alert("test")
, that should work.
回答2:
Some notes:
- You must add it to a keyset, as the key listeners are attached when keyset is added
- You must set an
oncommand
attribute
Can copy paste this to scratchpad:
var keyset = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul', 'keyset'); //http://forums.mozillazine.org/viewtopic.php?f=19&t=2711165&p=12885299&hilit=mainKeyset#p12885299 //cant use mainKeyset see topic above var key = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul', 'key'); var props = { id: 'key_convert', modifiers: 'accel', keycode: 'VK_F12', oncommand: 'alert("tirggered")' }; for (var p in props) { key.setAttribute(p, props[p]); } keyset.appendChild(key); Services.wm.getMostRecentWindow('navigator:browser').document.documentElement.appendChild(keyset);