[英]Cordova backbutton not working
I have a problem that Cordova event on the Back button does not do anything yet to execute alert (""). 我有一个问题,“返回”按钮上的Cordova事件尚未执行警报(“”)操作。
It is interesting that the code looks like it's perfectly fine and I did not even forget to introduce cordova.js
the only thing I can think is that it is necessary to wash a plug-in, Because I do not have any established. 有趣的是,代码看起来非常完美,我什至没有忘记介绍cordova.js
,我唯一能想到的就是有必要清洗插件,因为我没有建立任何插件。
My code looks like this: 我的代码如下所示:
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height" />
<link rel="stylesheet" href="css/phonon.css" />
<style>
.uvitani {
font-size: 250%;
margin: 0;
color: white;
position: absolute;
top: 40%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%)
}
.tlacitko {
margin: 0;
color: #0084e7;
background-color: white;
position: absolute;
bottom: 0;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%)
}
</style>
</head>
<script type="text/javascript" charset="utf-8">
function barva() {
alert(cordova.platformId);
if (cordova.platformId == 'android') {
StatusBar.backgroundColorByHexString("#0065b3");
}
document.addEventListener("backbutton", onBackKeyDown, false);
function onBackKeyDown() {
alert("Back");
}
}
</script>
<body style="background-color: #0084e7;" onload="barva();">
<center>
<p class="uvitani">Vítejte v aplikaci ISAS</p>
<button class="btn tlacitko" onclick='document.location="styl.html";'>Pokračovat</button>
</center>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script src="js/phonon-core.js"></script>
<script src="js/components/forms.js"></script>
<script src="js/components/preloaders.js"></script>
<script src="js/components/dialogs.js"></script>
</body>
</html>
Please passed some characters in alert box and return to false, 请在警报框中传递一些字符,然后返回false,
function barva() {
alert(cordova.platformId);
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady(){
if (cordova.platformId == 'android') {
StatusBar.backgroundColorByHexString("#0065b3");
}
document.addEventListener("backbutton", onBackKeyDown, false);
}
function onBackKeyDown(){
alert('back');
return false;
}
for more help check to here . 如需更多帮助,请查看此处 。
please check your plugin , 请检查您的插件,
you need to add following plugin in your project 您需要在项目中添加以下插件
cordova plugin add org.apache.cordova.statusbar
Hopes this will help you !!! 希望这对您有帮助!
It was enough to fix statusbar color ( I/chromium(18807): [INFO:CONSOLE(37)] "Uncaught ReferenceError: StatusBar is not defined", source: file:///android_asset/www/login.html (37)
) and now it works. 修复状态栏颜色就足够了( I/chromium(18807): [INFO:CONSOLE(37)] "Uncaught ReferenceError: StatusBar is not defined", source: file:///android_asset/www/login.html (37)
),现在可以使用了。
<script type="text/javascript" charset="utf-8">
function barva() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
if (cordova.platformId == 'android') {
StatusBar.backgroundColorByHexString("#0065b3");
}
document.addEventListener("backbutton", onBackKeyDown, false);
}
function onBackKeyDown() {
alert("back");
return false;
}
</script>
Thank you for your help. 谢谢您的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.