I'm creating an extension for google chrome that when the user clicks the "Copy!" button, execute this function on the web page
Asked
Active
Viewed 77 times
2
-
FYI you might have much better luck tagging your question with chrome extension and changing the title to something like "How to run script on page from chrome extension context" – The Muffin Man Jul 21 '19 at 07:58
-
Possible duplicate of [onClick within Chrome Extension not working](https://stackoverflow.com/questions/13591983/onclick-within-chrome-extension-not-working) – wOxxOm Jul 21 '19 at 14:34
1 Answers
3
onclick="execute()"
this won't run, since you can't use inline JavaScript
in html file for chrome extensions.
So trying adding click
event listenter on copy button using JavaScript, like so:
document.addEventListener('DOMContentLoaded', function () {
document.querySelector('input').addEventListener('click', execute);
});

makkBit
- 373
- 2
- 14
-
just remove `onclick="execute()"` all together. It would look like this:` ` You don't need this, since click event and the event handler `execute` is added in JS. – makkBit Jul 21 '19 at 07:16
-
Is giving error in js: Uncaught TypeError: Cannot read property 'addEventListener' of null at HTMLDocument.
(popup.js:2) – Jul 21 '19 at 07:28 -