У меня проблема с приложением Cordova.
Кнопки в index.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 *; img-src 'self' data: content:;"> -->
К сожалению, это не помогло.
index.html
<html><head><meta charset="utf-8" />
<!-- <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 *; img-src 'self' data: content:;"> -->
<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">
<title>Hello World</title>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript"> app.initialize();</script>
</head>
<body onload="engage()">
<div class="app">
<h1>Hello</h1>
<div><button onclick="setDeviceAlias()">Set Device Alias</button></div>
<div><button onclick="getAlias()">Get Device Alias</button></div>
<div><button onclick="removeDeviceAlias()">Remove Device Alias</button></div>
</div>
</body>
index.js
var app = {
initialize: function() {
this.bindEvents();
},
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function() {
document.addEventListener("resume", onResume, false);
app.receivedEvent('deviceready');
console.log('Received Event: ' + id);
},
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
}
};
app.initialize();
function onResume() {}
function engage() {}
function setDeviceAlias() {
Plugin.setDeviceAlias("someAlias",
function (json) {
alert(JSON.stringify(json));
}, function (json) {
alert(JSON.stringify(json));
});
}
function getAlias() {
Plugin.getAlias(function (json) {
alert(JSON.stringify(json));
}, function (json) {
alert(JSON.stringify(json));
});
}
function removeDeviceAlias() {
Plugin.removeDeviceAlias("",
function (json) {
alert(JSON.stringify(json));
}, function (json) {
alert(JSON.stringify(json));
});
}