javascript - Chrome extension: Click event in tab? -


hej,

i'm searching chrome api whole day can't find answer. quick: possible add icon tab , append click listener? or click listener on tab in general?

thanks!

yes it's possible chrome.tabs.executescript api. or content_scripts:

injectedscript.js

document.getelementbyid('btn1').addeventlistener('click',function () {     alert('button click!'); }); 

manifest.json

"content_scripts": [     {       "matches": ["http://www.example.com/webpage.html"],       "js": ["injectedscript.js"]     } ], 

webpage.html

<button id="btn1">clickme!</button>

for more information see programmatic injection

edit:

you can't add event tab itself, think best way this, context menu. example it's ugly code make work... (and i'm sorry english).

manifest.json

 "background":{"scripts":["background.js"]},   "permissions": ["contextmenus", "tabs","activetab","<all_urls>"] 

background.json

function apdatetablist() {     chrome.contextmenus.removeall(function() {         chrome.tabs.query({url:'*://*/*'}, function (tabs) {             var currtab;             (var i=0; currtab = tabs[i];i++) {                 chrome.contextmenus.create({                     id : currtab.id.tostring(),                     title: currtab.title || currtab.url,                     contexts:['all'],                     onclick : function(info) {                         chrome.tabs.executescript(number(info.menuitemid), {code:'alert("injected")'});                     }                 });             }         });     }); } apdatetablist(); chrome.tabs.oncreated.addlistener(apdatetablist); chrome.tabs.onupdated.addlistener(apdatetablist); chrome.tabs.onmoved.addlistener(apdatetablist); chrome.tabs.ondetached.addlistener(apdatetablist); chrome.tabs.onattached.addlistener(apdatetablist); chrome.tabs.onremoved.addlistener(apdatetablist); chrome.tabs.onreplaced.addlistener(apdatetablist); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -