Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Firefox键盘快捷键是否仅在浏览器启动时激活?_Javascript_Firefox_Firefox Addon_Firefox Addon Restartless - Fatal编程技术网

Javascript Firefox键盘快捷键是否仅在浏览器启动时激活?

Javascript Firefox键盘快捷键是否仅在浏览器启动时激活?,javascript,firefox,firefox-addon,firefox-addon-restartless,Javascript,Firefox,Firefox Addon,Firefox Addon Restartless,在Firefox无重启插件中,禁用和启用该插件后,键盘快捷键将消失。控制台不记录任何错误(try{}catch{}) 在检查浏览器工具箱时,将键插入到中,但快捷方式不起作用,并且修改器不会出现在上下文菜单上 所以问题是,我是否错过了一些东西,或者键盘快捷键只在浏览器启动时才被激活?我发现了问题 虽然键集和上下文菜单项的(创建/插入)顺序在浏览器启动时并不重要,但在重新启用无重启插件时却很重要。将键集创建/插入移动到菜单项创建/插入之前,解决了问题 let contextMenu = window

在Firefox无重启插件中,禁用和启用该插件后,键盘快捷键将消失。控制台不记录任何错误(
try{}catch{}

在检查
浏览器工具箱
时,将
插入到
中,但快捷方式不起作用,并且修改器不会出现在上下文菜单上


所以问题是,我是否错过了一些东西,或者键盘快捷键只在浏览器启动时才被激活?

我发现了问题

虽然
键集
上下文菜单项
的(创建/插入)顺序在浏览器启动时并不重要,但在重新启用无重启插件时却很重要。将
键集
创建/插入移动到
菜单项
创建/插入之前,解决了问题

let contextMenu = window.document.getElementById('contentAreaContextMenu');

/* keyset */
let mainKeyset = window.document.getElementById('mainKeyset'); // parent -> #main-window
let keyset = window.document.createElement('keyset');
//keyset.setAttribute('id', this.id + '-keyset'); // if you need to have an id
let key = window.document.createElement('key');
key.setAttribute('id', this.id + '-key');
key.setAttribute('modifiers', 'accel shift');
key.setAttribute('keycode', 'VK_F2');
key.setAttribute('oncommand', 'void(0);');
key.addEventListener('command', this, false);
keyset.appendChild(key); // add the key to keyset
mainKeyset.parentNode.appendChild(keyset);  // add the keyset to the window.document

/* ContextMenu Menuitem */
let docfrag = window.document.createDocumentFragment(); // temporary container
let menuseparator = window.document.createElement('menuseparator');
let menuitem = window.document.createElement('menuitem');
//menuitem.setAttribute('id', this.id + '-menuitem'); // if you need to have an id
menuitem.setAttribute('class', 'menuitem-iconic');
menuitem.setAttribute('label', this.menuitemLabel);
//menuitem.setAttribute('hidden', 'true'); // starts from hidden
menuitem.setAttribute('accesskey', 'R');
menuitem.setAttribute('key', this.id + '-key');
//menuitem.style.listStyleImage = 'url(chrome://' + this.id  + '/skin/icon16.png)'; // this also works
menuitem.setAttribute('style', 'list-style-image: url(chrome://' + this.id  + '/skin/icon16.png);');
menuitem.addEventListener('command', this, false);

docfrag.appendChild(menuseparator); // adding the menuseparator to temporary container
docfrag.appendChild(menuitem); // add the menuitem to temporary container
contextMenu.appendChild(docfrag); // add the temporary container to the contextMenu
每个请求:
首先我有
/*上下文菜单菜单项*/
部分,然后是
/*键集*/
部分。 通过将/*keyset*/
部分放在第一位,在插入
contextmenu菜单项之前创建并插入了keyset
,从而解决了问题

let contextMenu = window.document.getElementById('contentAreaContextMenu');

/* keyset */
let mainKeyset = window.document.getElementById('mainKeyset'); // parent -> #main-window
let keyset = window.document.createElement('keyset');
//keyset.setAttribute('id', this.id + '-keyset'); // if you need to have an id
let key = window.document.createElement('key');
key.setAttribute('id', this.id + '-key');
key.setAttribute('modifiers', 'accel shift');
key.setAttribute('keycode', 'VK_F2');
key.setAttribute('oncommand', 'void(0);');
key.addEventListener('command', this, false);
keyset.appendChild(key); // add the key to keyset
mainKeyset.parentNode.appendChild(keyset);  // add the keyset to the window.document

/* ContextMenu Menuitem */
let docfrag = window.document.createDocumentFragment(); // temporary container
let menuseparator = window.document.createElement('menuseparator');
let menuitem = window.document.createElement('menuitem');
//menuitem.setAttribute('id', this.id + '-menuitem'); // if you need to have an id
menuitem.setAttribute('class', 'menuitem-iconic');
menuitem.setAttribute('label', this.menuitemLabel);
//menuitem.setAttribute('hidden', 'true'); // starts from hidden
menuitem.setAttribute('accesskey', 'R');
menuitem.setAttribute('key', this.id + '-key');
//menuitem.style.listStyleImage = 'url(chrome://' + this.id  + '/skin/icon16.png)'; // this also works
menuitem.setAttribute('style', 'list-style-image: url(chrome://' + this.id  + '/skin/icon16.png);');
menuitem.addEventListener('command', this, false);

docfrag.appendChild(menuseparator); // adding the menuseparator to temporary container
docfrag.appendChild(menuitem); // add the menuitem to temporary container
contextMenu.appendChild(docfrag); // add the temporary container to the contextMenu

既然你自己解决了这个问题(太好了!),正确的方法是回答你自己的问题并接受你自己的答案,而不是编辑你的问题;)谢谢分享男人。你能发布你在修复之前和之后所做的代码吗?这会有很大帮助。@Noitidart。。。我把最后的密码给你。before代码完全相同,但
/*键集*/
部分位于
/*上下文菜单菜单项*/