我正在开发一个Chrome扩展程序,并将命令
我希望可以通过不同的快捷键调用
在我的manifest.json中声明了以下内容:
这是我的background.js文件:
我想知道如何触发这个动作,以便打开我的popup.html。
_execute_browser_action
分配给Alt+J。 我想在background.js中模拟这个命令,通过监听所有命令实现此功能。chrome.commands.onCommand.addListener(function(command) { /* ... */ });
我希望可以通过不同的快捷键调用
_execute_browser_action
,比如说用Cmd+Shift+K。在我的manifest.json中声明了以下内容:
"commands": {
"_execute_browser_action": {
"suggested_key": {
"mac": "Alt+J",
"linux": "Ctrl+Shift+J"
}
},
"asdf" : {
"suggested_key": {
"default": "Ctrl+Shift+K",
"mac": "Command+Shift+K"
},
"description": "asdf"
}
}
这是我的background.js文件:
chrome.commands.onCommand.addListener(function(command) {
console.log('onCommand event received for message: ', command);
if (command === "asdf") {
alert("asdf");
var keyPress = jQuery.Event("keypress");
keyPress.altKey = true;
keyPress.ctrlKey = false;
keyPress.which = 74;
//how do I trigger this?
}
});
我想知道如何触发这个动作,以便打开我的popup.html。