body onload works on galaxy tab but not xt1080 with cordova

91 Views Asked by At
<!DOCTYPE html>

    <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 *">
    <meta name="format-detection" content="telephone=no">
    <meta name="msapplication-tap-highlight" content="no">
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
    <link rel="stylesheet" type="text/css" href="css/index.css">
    <script type="text/javascript" src="cordova.js"></script>
    <script>
        function onLoad() {
            alert('onLoad');
        }
    </script>
    <title>Hello World</title>
</head>
<body onload="onLoad();">
    <div class="app">
        <h1>Apache Cordova</h1>
        <div id="deviceready" class="blink">
            <p class="event listening">Connecting to Device</p>
            <p class="event received">Device is Ready</p>
        </div>
    </div>
</body>

On the xt1080, this shows no alert.

On the galaxyTab this shows the alert.

Why does this not work on the xt1080?

I created the files by doing cordova create test followed by cordova platforms add android followed by cordova plugin add cordova-plugin-device and then modified the index.html to the above.

xt1080: 4.4.4

gt: 4.2.2

1

There are 1 best solutions below

0
On

Later versions of chrome are more restrictive on inline scripts.

Run it and watch console output. If you get a "Refused to execute inline event handler" type message then add 'unsafe-inline' to your default source in the content security policy of your config.xml file.

<meta http-equiv="Content-Security-Policy" content="default-src 'self'   
data: gap: https://ssl.gstatic.com 'unsafe-inline' 
'unsafe-eval'; style-src 'self'; media-src *;">

Details on the policies are available at https://developer.chrome.com/extensions/contentSecurityPolicy .

Hope this helps. Healy in Tampa.