Chrome Extension: Submit button to activate script -
this question has answer here:
so i'm trying make extension runs script when submit button pressed. since google chrome extensions cannot have scripts directly inside html security reasons, need have external script. how call function external script submit button?
this i've tried far:
here's popup.html:
<html> <head> <!--css styling removed here--> <script src="popup.js"></script> </head> <body> <!--html page working fine, button not--> <input type="submit" value="submit" onclick="convert();"> <p id="p2">value</p> </body> </html>
(i've tried calling popup.convert();
, doesn't work either)
and here's popup.js:
function convert(){ document.getelementbyid("p2").innerhtml = "hello!"; }
i'm trying change p element in extension popup, not webpage.
thanks in advance!
edit: suggested question duplicate of this: onclick within chrome extension not working
that didn't help, although did give me link https://developer.chrome.com/extensions/contentsecuritypolicy#jsexecution semi-helpful.
the problem solution on other question is not button link. (thanks pointing me topic anyway!)
html markup language , contains markup:
<input id="convert-submit" type="submit" value="submit">
the script should attach events elements once popup document body loaded (you reference script in <head>
it's executed when <body>
hasn't been parsed yet):
document.addeventlistener("domcontentloaded", function() { document.getelementbyid("convert-submit").addeventlistener("click", convert); });
Comments
Post a Comment