kango framework - extension appearing in the context menu of the browsers -
I am developing a cross browser extension using the Congo framework. I want to add my extension to the browser's context menu. I have already set up "context_menu": the extension_info.json file is correct in the permissions array, but my extension does not appear in the context menu (when there is a right click in the browser window). how can I do this?
You need to add an event listener to main.js like this:
kango.ui.contextMenuItem.addEventListener (kango.ui.contextMenuItem.event.CLICK, function () {kango.browser.tabs.getCurrent (function (tab) {tab.dispatchMessage ('ContextMenuItemClick');}) ;}); And in content.js you need to consume such an event:
function handleContextMenuClick () {var clickedElement = null; If (document 'addEventListener') {document.addEventListener ('mousedown', function (event) {if (event.button == 2 & amp; IsSupported ()) {clickedElement = event.target; kango.console .log ('StopIt menu item 1 click on');}}, true); } Else {document.attachEvent ('onmousedown', ceremony (event) {event = event || window.event, if (event.button == 2 & amp; IsSupported ()) {clickedElement = event.srcElement; Kango.console .log (Click 'StopIt menu item 2');}}); } Kango.addMessageListener ('ContextMenuItemClick', function (event) {kango.console.log ("addMessageListener: ContextMenuItemClick added");}); } HandleContextMenuClick (); // Only when the user is on Facebook or Twitter, activate the menu // It should be loaded from a service and each new domain visited function is Supported () {if (document.domain.indexOf ("facebook.") Gt; -1) Returns correct; If (document.domain.indexOf ("twitter.") Gt; -1) returns true; return false; }
Comments
Post a Comment