locked
Apache Cordova Visual Studio 2017 How to call Javascript function RRS feed

  • Question

  • User1203305613 posted

    Hi All,

    I am coding a small Calorie Calculator using Apache Cordova (HTML5 ,JS), on click I want to call a JS function which is not inline(its  a separate library ) that wouldn't work .

    </head>
    <body>
    <div data-role="page" id="weather-page">

    <div data-role="header" class="header">
    <h1 id="app-title">Weather App</h1>
    <a href="/" class="ui-btn ui-btn-left ui-btn-corner-all ui-icon-home ui-btn-icon-notext" rel="external">Home</a>
    </div>

    <div role="main" class="ui-content">
    <form>
    <label for="Weight">Type your Weight:</label>
    <input id="Weight-input" type="number" name="weight" placeholder="In Kgs" min="40" max="120" required /> <br />
    <label for="Height">Type your Height:</label>
    <input id="Height-input" type="number" name="height" placeholder="In cms" min="80" max="210" required /> <br />
    <label for="Age ">Type your Age :</label>
    <input id="Age-input" type="number" name="age" min="12" max="80" required /> <br />
    <input type="radio" name="gender" value="male" checked> Male<br>
    <input type="radio" name="gender" value="female"> Female<br>
    <button id="get-weather-btn" data-role="button" onclick="Calc()" data-icon="search">Find Daily Calories</button>
    </form>

    </div>
     
    <script type="text/javascript" src="scripts/Calcscript.js"></script>

    </body>

    </html>

    --------------------

    Calcscript.js file

    -------------------

    function Calc()
    {
    console.log("Hicalc");
    return true;
    }

    Sunday, March 10, 2019 7:01 AM

Answers

  • User283571144 posted

    Hi KALYANA ALLAM,

    According to your description, I guess you may not enable the inline src in the meta http-equiv="Content-Security-Policy".

    I suggest you could try to add the 'unsafe-inline' to default-src to enable the inline src.

    Like below:

            <meta http-equiv="Content-Security-Policy" content="default-src  'self' 'unsafe-inline' data: gap:  http://localhost ; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;">
    

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 11, 2019 4:55 AM

All replies

  • User283571144 posted

    Hi KALYANA ALLAM,

    According to your description, I guess you may not enable the inline src in the meta http-equiv="Content-Security-Policy".

    I suggest you could try to add the 'unsafe-inline' to default-src to enable the inline src.

    Like below:

            <meta http-equiv="Content-Security-Policy" content="default-src  'self' 'unsafe-inline' data: gap:  http://localhost ; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;">
    

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 11, 2019 4:55 AM
  • User1203305613 posted

    Thanks soo much Brando , you guess it correct and it fixed my issue.I am able to call Javascript inline

    Tuesday, March 12, 2019 12:26 PM