Am developing a chrome extension. Am injecting a script in a wbpage using contentscript as follows:
var s = document.createElement('script');
s.src = chrome.extension.getURL("script.js");
(document.head||document.documentElement).appendChild(s);
My script.js:
$.post("https://www.example.com/srv/example/", function(html){
$("body").prepend(html);
});
Now, i would like to listen to a button click event in the webpage DOM ? How to achieve this?
You can listen with
document.body.addEventListener('click', yourListenerFunction, true);
BTW, you're executing your content script in a very odd way. The usual is using some code in your background.js, like:
chrome.tabs.executeScript(tabId, {file:"yourScriptFile.js"});
I recommend this https://developer.chrome.com/extensions/overview
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With