[Cordova] Unable to display alert window problem scenario
Today, I opened a Cordova project to do an example of modifying the preset index.html page to the following content. Pressing execution found that such a simple example could not be performed properly. There is no way to display the Alert window by clicking the Click me button on the page.
<!DOCTYPE html>
Solution SolutionsAfter troubleshooting the code, it is found that the Cordova will add "content-security-policy" to this security setting in the preset state, and the Presets do not enable inline JavaScript. (In fact, the default page annotations are written ...)
Once you know the problem, simply add "' Unsafe-inline '" to the DEFAULT-SRC block in the Content-security-policy, which will allow the alert window to execute and display normally.
Before
<meta http-equiv="Content-Security-Policy" content="default-src ‘self‘ data: gap: https://ssl.gstatic.com ‘unsafe-eval‘; style-src ‘self‘ ‘unsafe-inline‘; media-src *">
After
<meta http-equiv="Content-Security-Policy" content="default-src ‘self‘ data: gap: https://ssl.gstatic.com ‘unsafe-eval‘ ‘ unsafe-inline‘; style-src ‘self‘ ‘unsafe-inline‘; media-src *">
[Cordova] cannot display alert window