开发者

Creating dynamic child context menu based on AJAX call

开发者 https://www.devze.com 2023-03-22 18:49 出处:网络
I\'m developing a chrome extension where I need to create dynamic sub-contextMenus based on some selected text. Like If you select a text, it\'ll send an ajaxrequest from the background.html and creat

I'm developing a chrome extension where I need to create dynamic sub-contextMenus based on some selected text. Like If you select a text, it'll send an ajaxrequest from the background.html and create some child context menu based on the returned results. Is that possible开发者_运维知识库? I've been trying for sometime. But no luck.


You can add right mouse button event listener in a content script:

document.addEventListener("mousedown", function(event){
        if(event.button == 2) {
                //get selected text and send request to bkgd page to create menu
        }
}, true);

There is also oncontextmenu event, can try it as well (I think mousedown is fired earlier though).

0

精彩评论

暂无评论...
验证码 换一张
取 消