2

I'm working vor my private phonegap project. I want to start the app and then to call an external website, which is stuffed with jquerymobile stuff. The first script in the app is a script which should wait until the device is ready and online. Then call the external link. But it doesn't work. Unfortunately I have no idea why not... Here it is (only the called js script): (in the website I load jquery and jquerymobile, there is no issue).

            var lat = "";
            var lng = "";
            var dat = "";
             devReady = false;
             devOnline = false;

            $(function(){
              document.addEventListener("deviceready", onDeviceReady, false);
              document.addEventListener("online", onOnline, false);
            })

            function onDeviceReady() {
                devReady = true;
                callExtPage();
            }

            function onOnline() {
                devOnline = true;
                callExtPage();
                }

            function callExtPage() {
                // calls the external Page when device is ready (parameters set) and online
                if(devOnline == true && devReady == true) {
                    navigator.geolocation.getCurrentPosition(function() {
                        lat = position.coords.latitude;
                        lng = position.coords.longitude;
                        dat = currentDate();
                    }, false);
                    // load an external page ($.mobile.changePage does only call as ajax)
                    window.location.href="http://www.mydomain.com/mobiles?lat="+lat+"&lng="+lng+"&dat="+dat;
                }
            }
            function currentDate() {
                var d = new Date();
                var curr_date = d.getDate();
                var curr_month = d.getMonth() + 1; //Months are zero based
                var curr_year = d.getFullYear();
                if(curr_date < 10) {curr_date = "0"+curr_date}
                if(curr_month < 10) {curr_month = "0"+curr_month}
                var currDate = curr_year+"-"+curr_month+"-"+curr_date;
                return currDate;
            }

Thank you for any help or shortcuts.

FishWave
  • 308
  • 2
  • 16

1 Answers1

0

Move the call to deviceready line as the first statement in yours section. Your current code, deviceready event hookup is not called at all.

<script>
 document.addEventListener("deviceready", onDeviceReady, false);

 function onDeviceReady() {
                devReady = true;
                callExtPage();
 }
</script> 
Nishanth Nair
  • 2,975
  • 2
  • 19
  • 22