Inline javascript is not permitted in background.html for security reasons. You should instead put the javascript code in a file such as script.js then add this <script src="script.js"></script> to your background.html file.
This is a discussion on "Refused to execute inline event handler" within the Plugins Development section, part of the Chrome Plugins category: Hello all, I'm currently writing my first Chrome extension as a little hobby and I've run across a problem. The ...
Hello all, I'm currently writing my first Chrome extension as a little hobby and I've run across a problem. The problem is:
Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'self' chrome-extension-resource:".
I have written a small calculator. The calculator works perfectly if I load up the HTML page and use it as anything but a Chrome extension. I've done some searching on my own and I was instructed to use the addEventListener() method rather than onClick(). I have done this but I still have the above problem for some reason. My popup.js code is as follows:
I have the button defined as:Code:document.addEventListener('DOMContentLoaded', function () { var calculate_button = document.getElementById('calculate_button'); calculate_button.addEventListener('click',calculateCrCl); });
The calculation function simply calculates the number and the sets the .value for a textbox to that number.Code:<button id="calculate_button">Calculate</button>
However, when I'm using the calculator as an extension, I get this security violation error and I'm not sure how to fix it.... any ideas?![]()
Inline javascript is not permitted in background.html for security reasons. You should instead put the javascript code in a file such as script.js then add this <script src="script.js"></script> to your background.html file.