09-08-2012 05:13 AM
why
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
document.addEventListener("backbutton", function(e) {
alert("hi");
console.log("Back button pressed!!!!");
window.history.back();
}, false);
}
this is not working in android...![]()
09-08-2012 06:15 AM
LBP, I'm like-ing all your replies just because I admire your patience so much ![]()
09-08-2012 06:19 AM
Thanks sir
09-08-2012 07:30 AM
Hi Nuno. THX, it's just fun to answer
but (@ravi1989) there are fundamental things like reading specs, reading API documentations, using Google or forum search before posting something here or in any other community forum.
@ravi1989: You should read and understand the Cordova/PhoneGap documentation for your backbutton event listener. All you need is in there. For the question about writing source code in HTML/JS/CSS I mainly use Notepad++ since I do not need a big IDE for most things. All you need is well documented frameworks and a knowledge about the things you are doing.
BTW: Working with Cordova/PhoneGap you need to use the different API implementations for the devices/OS? For every single supported device/OS they offer different .js framework files you need to use.
09-08-2012 09:39 AM
sir it still not working back button in android.........![]()
i used this code alert is not coming
document.addEventListener("backbutton", onBackKeyDown, false);
function onBackKeyDown() {
alert("gyu");
// Handle the back button
}
09-08-2012 10:24 AM
For Android development use Eclipse and the LogCat console to do some console.log or to get the errors in your app. The behaviour isn't really possible like you want it to work. In most cases the "back" button of the Android OS is bind to an OS functionality, so you can not really use it the way you want to without going into the Activity you are extending the DroidGap with.
BTW: Like many others mentioned before in this thread and also in many of the other threads you posted, this is a playground for BlackBerry devs in general. You might get an answer on your questions for whatever mobile OS you are referring to, but I think the first should be searching the web for your questions since almost all of them are already answered. And for your Cordova/Phonegap problems you can get an answer in the IRC or even in the Forum for it.
BTW2: Your problem might be an issue/bug of the Cordova/PhoneGap version you are using, the mobile OS version you run into an issue or you can find your answer in the forum post here by reading and understanding the provided source code. All you need should be in there.
09-11-2012 01:36 AM
Hi
Your code is working Fine in IOS
Bus there is problem in Android i don't know why this problem occur.?
<body onload="GetStationCodes()">
function GetStationCodes()
{
var r = JSON.parse(window.localStorage.getItem("stations") )||[];
if(r.length > 0){
document.getElementById('loadingImg').style.visibi lity = "hidden";
document.getElementById('submitBtn1').removeAttrib ute('disabled');
document.getElementById('submitBtn2').removeAttrib ute('disabled');
document.getElementById('submitBtn3').removeAttrib ute('disabled');
document.getElementById('getStationDesc').removeAt tribute('disabled');
if(window.localStorage.getItem("lastArrivalStation ")!=null){
document.getElementById("headingcontent").innerHTM L =window.localStorage.getItem("lastArrivalStation") ;
}
else{
document.getElementById("headingcontent").innerHTM L = "No station is selected.";
}
for (var i = 0; i < r.length-1; i++)
{
stationList[i] = r[i].stationCode + " - " + r[i].stationName;
}
}
else {
document.getElementById('loadingImg').style.visibi lity = "visible";
var pl = new SOAPClientParameters();
var parameter1 = "";
var parameter2 = "";
pl.add("parameter1", parameter1);
pl.add("parameter2", parameter2);
document.getElementById("headingcontent").innerHTM L = "No station selected.";
SOAPClient.invoke(WSDLURL, "stationSearch", pl, true, GetStationCodes_callBack);
}
}
i save here stations
function GetStationCodes_callBack(r)
{
document.getElementById('loadingImg').style.visibi lity = "hidden";
document.getElementById('submitBtn1').removeAttrib ute('disabled');
document.getElementById('submitBtn2').removeAttrib ute('disabled');
document.getElementById('submitBtn3').removeAttrib ute('disabled');
document.getElementById('getStationDesc').removeAt tribute('disabled');
window.localStorage.setItem("stations", JSON.stringify(r));
for (var i = 0; i < r.length-1; i++)
{
stationList[i] = r[i].stationCode + " - " + r[i].stationName;
}
}Error is : JSON is undefined
09-11-2012 06:57 AM
Strange issue. Is there any line number reported with the "JSON undefined" output?
09-11-2012 06:58 AM
1 sec i will tell you
09-11-2012 07:00 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Select Arrival Station</title> <link href="style/style.css" rel="stylesheet" type="text/css" /> <link href="style/scrollpanel.css" rel="stylesheet" type="text/css" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> <script language="javascript" type="text/javascript" src="script/actb.js"></script> <script language="javascript" type="text/javascript" src="script/actb2.js"></script> <script type="text/javascript" src="script/common.js"></script> <script type="text/javascript" src="script/soapclient.js"></script> <!--script type="text/javascript" src="cordova-1.9.0.js"></script--> <script type="text/javascript"> var stationList = new Array; function GetStationCodes() { var r = JSON.parse(window.localStorage.getItem("stations") )||[]; if(r.length > 0){ document.getElementById('loadingImg').style.visibi lity = "hidden"; document.getElementById('submitBtn1').removeAttrib ute('disabled'); document.getElementById('submitBtn2').removeAttrib ute('disabled'); document.getElementById('submitBtn3').removeAttrib ute('disabled'); document.getElementById('getStationDesc').removeAt tribute('disabled'); if(window.localStorage.getItem("lastArrivalStation ")!=null){ document.getElementById("headingcontent").innerHTM L =window.localStorage.getItem("lastArrivalStation") ; } else{ document.getElementById("headingcontent").innerHTM L = "No station is selected."; } for (var i = 0; i < r.length-1; i++) { stationList[i] = r[i].stationCode + " - " + r[i].stationName; } } else { document.getElementById('loadingImg').style.visibi lity = "visible"; var pl = new SOAPClientParameters(); var parameter1 = ""; var parameter2 = ""; pl.add("parameter1", parameter1); pl.add("parameter2", parameter2); document.getElementById("headingcontent").innerHTM L = "No station selected."; SOAPClient.invoke(WSDLURL, "stationSearch", pl, true, GetStationCodes_callBack); } } function GetStationCodes_callBack(r) { document.getElementById('loadingImg').style.visibi lity = "hidden"; document.getElementById('submitBtn1').removeAttrib ute('disabled'); document.getElementById('submitBtn2').removeAttrib ute('disabled'); document.getElementById('submitBtn3').removeAttrib ute('disabled'); document.getElementById('getStationDesc').removeAt tribute('disabled'); window.localStorage.setItem("stations", JSON.stringify(r)); for (var i = 0; i < r.length-1; i++) { stationList[i] = r[i].stationCode + " - " + r[i].stationName; } } function displayAllStation(){ if(document.getElementById('getStationDesc').value !=""){ window.location="arrival.html?getStationCode="+doc ument.getElementById('getStationCode').value+"&get StationDesc="+document.getElementById('getStationD esc').value; } else{ alert("Please select station."); } } function displayNextStation(){ if(document.getElementById('getStationDesc').value !=""){ window.location="nextarrivalstation.html?getStatio nCode="+document.getElementById('getStationCode'). value+"&getStationDesc="+document.getElementById(' getStationDesc').value; } else{ alert("Please select station."); } } </script> </head> <body onload="GetStationCodes()"> <div id="wrapper"> <div class="departure_cont"> <div class="home_icon"><a href="index.html"><img src="images/home-icon.png" alt="Home" title="Home" /></a></div> <h1 class="fr">Arrivals</h1> <div class="cl"></div> <h2 id="headingcontent"></h2> <div class="cl"></div> <ul> <li> <button type="submit" class="btn" id="submitBtn1" >Get Date</button> </li> <li> <button type="submit" id="submitBtn2" class="btn" onclick="FillValues();displayNextStation()" disabled="disabled">Next Train</button> </li> <li> <button type="submit" id="submitBtn3" class="btn" onclick="FillValues();displayAllStation()" disabled="disabled">All today</button> </li> </ul> <h3 style="text-align:left; float:left; margin-left:3%;">Change Location</h3> <div class="cl"></div> <form name="frmIndex" type=get> <div class="log_cont"> <input id="getStationDesc" name="getStationDesc" type="text" class="log_txtfield" disabled="disabled"/> <script> var obj = actb(document.getElementById('getStationDesc'),sta tionList); //$("#index").trigger("pagecreate"); //setTimeout(function(){obj.actb_keywords = custom2;},10000); this.actb_timeOut = -1; // Number of elements autocomplete can show (-1: no limit) this.actb_lim = 10; // should the auto complete be limited to the beginning of keyword? this.actb_firstText = true; // Enable Mouse Support this.actb_mouse = true; // Delimiter for multiple autocomplete. // Set it to empty array for single autocomplete this.actb_delimiter = new Array(' ',','); // Show widget only after this number of characters is typed in. this.actb_startcheck = 1; this.actb_bgColor = '#dbe3ec'; this.actb_textColor = '#00256a'; this.actb_hColor = '#dbe3ec'; this.actb_fFamily = 'arial'; this.actb_fSize = '16px'; this.actb_hStyle = 'text-decoration:underline;font-weight="bold;";tex t-align="left"'; function FillValues() { document.getElementById('getStationCode').value = document.getElementById('getStationDesc').value.su bstring(0,3); if(window.localStorage.getItem("lastArrivalStation ")!=null){ window.localStorage.removeItem("lastArrivalStation "); } window.localStorage.setItem("lastArrivalStation",d ocument.getElementById('getStationDesc').value); } </script> <div> <img src="images/ajax-loader.gif" id="loadingImg" visible =true style="margin:auto; position: absolute; left:50%; top:50%;"/> </div> <input id="getStationCode" name="getStationCode" type="hidden" /> </div> </form> </div> </div> </body> </html>
This is my code...LIne number 22
var r = JSON.parse(window.localStorage.getItem("stations")