Creating dynamic child context menu based on AJAX call
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).
精彩评论