So I'm trying to make an extension that runs a script when a submit button is pressed. Since Google Chrome extensions cannot have the scripts directly inside the HTML for security reasons, I need to have an external script. How do I call a function from an external script with the submit button?
This is what I've tried so far:
Here's the popup.html:
<html>
<head>
<!--css styling removed from here-->
<script src="popup.js"></script>
</head>
<body>
<!--html page is working fine, only the button is not-->
<input type="submit" value="Submit" onclick="convert();">
<p id="p2">Value</p>
</body>
</html>
(I've also tried calling
popup.convert();
, but that doesn't work either)
And here's the popup.js:
function convert(){
document.getElementById("p2").innerHTML = "Hello!";
}
I'm trying to change the p element in my extension popup, not the webpage.
Thanks in advance!
EDIT: It was suggested that my question was a duplicate of this: onClick within Chrome Extension not working
That didn't really help, although it did give me a link to https://developer.chrome.com/extensions/contentSecurityPolicy#JSExecution which was semi-helpful.
The problem with the solution on the other question is that it is not a button but a link. (Thanks for pointing me to that topic anyway!)