2

私は自分のプライベート phonegap プロジェクトに取り組んでいます。アプリを起動してから、jquerymobile が詰め込まれた外部 Web サイトを呼び出したいと考えています。アプリの最初のスクリプトは、デバイスの準備が整いオンラインになるまで待機するスクリプトです。次に、外部リンクを呼び出します。しかし、うまくいきません。残念ながら、私には理由がわかりません...ここにあります(呼び出されたjsスクリプトのみ):(jqueryとjquerymobileをロードするWebサイトでは、問題はありません)。

            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;
            }

ヘルプやショートカットをありがとう。

4

1 に答える 1

0

あなたのセクションの最初のステートメントとして、deviceready 行への呼び出しを移動します。現在のコードの deviceready イベント フックアップはまったく呼び出されません。

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

 function onDeviceReady() {
                devReady = true;
                callExtPage();
 }
</script> 
于 2013-04-12T18:38:00.507 に答える