I have the follwing code in the content.js of Google Chrome extension:
jQuery(document).ready(function () {
jQuery("body").html('<input type="button" id="soso" value="asd" onclick="goFrame()" />');
});
function goFrame() {
alert('Value');
}
The button is created successfully, but when I click on it the message doesn’t appear and I got the follwing error in the Google Chrome console:
Uncaught ReferenceError: goFrame is not defined
First read Chrome extension code vs Content scripts vs Injected scripts.
To solve the problem, get rid off the inline event listener, and bind the event dynamically: