javascript - Message passing by chrome.runtime.sendMessage()? -
i refered chrome documentation https://developer.chrome.com/apps/runtime#type-messagesender https://developer.chrome.com/apps/runtime#event-onmessage
in sample chrome extension, pass number contentscript.js popup.js:
contentscript.js:
var fromdom = 100; chrome.runtime.sendmessage({fromdom});//here i'm passing value in fromdom
popup.js:
chrome.runtime.onmessage.addlistener(function(response){ number = response; //here i'm assigning value in response total document.getelementbyid("output").innerhtml=number;//manipulating element // in popup.html } );
the element "output" isn't getting modified.
so, doing right? how should "any message" parameter in general , can use parameter way?
updated contenscript.js , background.js:
contenscript.js:
//code values table in results page var table = document.getelementsbyclassname("collapse")[0]; var marks = new array(); for(var i=0;i<8;i++) marks[i] = table.children[0].children[i+1].children[5].innerhtml; var total=0; for(var i=0;i<8;i++) total += number(marks[i]); var fromdom = total; chrome.runtime.sendmessage(fromdom);
background.js:
//code display pageaction button on domain results.griet.in chrome.runtime.oninstalled.addlistener(function() { chrome.declarativecontent.onpagechanged.removerules(undefined, function() { chrome.declarativecontent.onpagechanged.addrules([{ conditions: [ new chrome.declarativecontent.pagestatematcher({ pageurl: { hostsuffix:<website> } }) ], actions: [new chrome.declarativecontent.showpageaction()] }]); }); }); //code inject contentscript. chrome.tabs.executescript({"file": "contentscript.js"});
Comments
Post a Comment