Javascript:延迟显示上下文菜单(Chrome)
我正在尝试在 Chrome 扩展程序中动态创建上下文菜单项;这涉及到向主扩展进程发送修改菜单的请求,并阻止菜单显示,直到发送响应为止。我一整天都在尝试不同的解决方案,但还没有想出一个有效的解决方案。例如,
node.oncontextmenu = initContext({...});
initContext = function(menuParams) {
return function(event) {
if (event.showContext) // Menu has been created and is ready for display
return true;
event.preventDefault(); // Block original menu event
chrome.extension.sendRequest(menuParams, function() { // Send request to modify menu,
event.showContext = true; // generate new event when menu is ready
event.target.dispatchEvent(event);
});
};
};
使用 PreventDefault() 阻止菜单,并在菜单准备好显示时执行 chrome.extension.sendRequest() 的回调函数。使用此解决方案(以及我尝试过的所有其他解决方案),菜单永远不会显示。我将不胜感激任何帮助。
I'm trying to dynamically create context menu items in a Chrome extension; this involves sending a request to the main extension process to modify the menu, and blocking the menu from being displayed until a response is sent. I've been experimenting with different solutions all day, and I have yet to come up with one that works. For example,
node.oncontextmenu = initContext({...});
initContext = function(menuParams) {
return function(event) {
if (event.showContext) // Menu has been created and is ready for display
return true;
event.preventDefault(); // Block original menu event
chrome.extension.sendRequest(menuParams, function() { // Send request to modify menu,
event.showContext = true; // generate new event when menu is ready
event.target.dispatchEvent(event);
});
};
};
The menu is blocked with preventDefault(), and the callback function to chrome.extension.sendRequest() is executed when the menu is ready to be displayed. With this solution (and all the others I've tried), the menu is never displayed. I'd appreciate any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论