[Cordova] Cannot display alert window

Source: Internet
Author: User

[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 Solutions

After 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 ...)

    • Preset page annotations

      <!--    视需要在下方的中继标签中自订内容安全性原则。将‘unsafe-inline‘ 加入default-src 以启用内嵌JavaScript。    如需详细资料,请参阅http://go.microsoft.com/fwlink/?LinkID=617521-->

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.