Reputation: 331
I have a index page and many button on that index page. Clicking those button page will go to some other pages. I have this code on index.htlm
<script type="text/javascript" charset="utf-8" src="jquery-mobile/cordova-1.8.1.js"></script>
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
document.addEventListener("backbutton", onBackKeyDown, false);
}
function onBackKeyDown() {
alert("Are you sure !!")
}
<body onLoad="onLoad()"> </body>
So when I am in the index page back button should only give that alert. I have no problem with that, the alert is showing properly but back button is disabled from other page also.
Upvotes: 0
Views: 960
Reputation: 348
Try adding after your alert:
document.removeEventListener("backbutton", onBackKeyDown, false);
Upvotes: 0
Reputation: 4866
<head>
section<head> <script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"> <!-- Other JS files .... --> </head>
Upvotes: 1
Reputation: 2424
You are not checking the page in your function, so it reacts equally for every page. Try this:
function onBackKeyDown() {
if($.mobile.activePage.is('#homepage')){
e.preventDefault();
alert("Are you sure !!");
}
else {
navigator.app.backHistory()
}
}
Upvotes: 1