public
Created

Phonegap Backbutton Test

  • Download Gist
home.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
<!DOCTYPE HTML>
<html>
<head>
<title>Home</title>
</head>
 
<body>
 
<div id="homePage" data-role="page">
<div data-role="header" data-position="inline">
<!-- <a href="#" id="infoLink" data-icon="info" data-iconpos="notext">Info</a> -->
<h1>Home</h1>
</div>
 
<div data-role="content" >
This is home page</div>
 
</div>
</body>
</html>
index.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
<!DOCTYPE HTML>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1"/>
<link rel="stylesheet" href="css/jquery.mobile-1.0rc1.min.css" />
 
</head>
<body >
 
<div id="indexPage" data-role="page" >
 
<div data-role="header" >
<h1>Index Page</h1>
</div>
 
<div data-role="content" >
<a href="home.html" data-role="button" >Home Link</a>
<a href="#" data-role="button" id="home" >Home Script</a>
</div>
<div data-role="footer" data-position="fixed">
<div data-role="navbar">
<ul>
<li><a href="home.html" data-transition="none">1</a>
</li>
<li><a href="home.html" data-transition="none">2</a>
</li>
<li><a href="home.html" data-transition="none">3</a>
</li>
</ul>
</div>
<!-- /navbar -->
</div>
</div>
 
<script src="js/jquery.js"></script>
<script src="js/phonegap.js"></script>
<script src="js/jquery.mobile.js"></script>
<script type="text/javascript">
$("#home").click(function(){
$.mobile.changePage("home.html");
});
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap loaded
 
function onDeviceReady() {
console.log("PhoneGap Ready!");
// waiting for button
document.addEventListener("backbutton", handleBackButton, false);
}
 
// handle the back button
function handleBackButton() {
console.log("Back Button Pressed!");
navigator.app.exitApp();
}
</script>
</body>
</html>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.