2016-12-07 102 views
0

我正在開發PhoneGap構建中的測試應用程序。目前,我正在嘗試在應用加載時重定向到一個頁面。但是當我嘗試這樣做時,它不會重定向,而只能保留在index.html頁面中。我正在使用TestObject來測試應用程序。Phonegap構建 - Javascript無法正常工作

的index.html

<!DOCTYPE html> 
<html> 
    <head> 
     <script type="text/javascript" charset="utf-8"> 
      function init() { 
       document.addEventListener("deviceready", onDeviceReady, true); 
      } 

      function onDeviceReady() { 
       alert("Device is ready"); 
      } 

     </script> 
    </head> 
    <body onload="init();"> 
     <input type="button" onclick="location.href='http://google.com';" value="Go to Google" /> 
     Hai welcome to my app 
    </body> 
</html> 

config.xml中

<?xml version="1.0" encoding="UTF-8" ?> 
    <widget xmlns = "http://www.w3.org/ns/widgets" 
     xmlns:gap = "http://phonegap.com/ns/1.0" 
     id   = "com.mydomain.mobileApp" 
     versionCode = "1" 
     version  = "1.0.0" > 

    <!-- versionCode is Android only --> 
    <!-- version is in major.minor.patch format --> 
    <name>My App</name> 

    <description> 
     An example for phonegap build app which wont show up in the playstore. 
    </description> 

    <author href="https://YourWebsite.com" email="[email protected]"> 
     Name Of The Author 
    </author> 

</widget> 

當我測試這個瀏覽器,在單擊按鈕,它會重定向到http://google.com。但是當我上傳apk(從phonebuild構建)並上傳到TestObject時,按鈕即將到來。但點擊它沒有任何反應。當我測試應用程序時,我越來越喜歡這個。

enter image description here

誰能幫我找到這個問題。提前致謝。

+0

http://phonegap.com/getstarted/請按照教程和嘗試指定你的問題。 –

+0

你在使用phonegap-cli還是phonegap-app-desktop? –

+0

@ HassanALi ..我使用phonegap build .. – Jenz

回答

0

在HTML文件的head部分包括phonegap.js,不要使Click事件處理程序內聯。在script部分註冊事件處理程序。並確保您已包含whitelist插件。試試下面的代碼:

<!DOCTYPE html> 
<html> 
    <head> 
     <script type="text/javascript" src="phonegap.js"></script> 
     <script type="text/javascript"> 
     function myFun(){ 
      document.getElementById("myBtn").addEventListener("click", function(){ 
      location.href='http://google.com'; 
      }); 
     } 

     </script> 
    </head> 
    <body onload="myFun()"> 
     <button id="myBtn">Go to Google</button> 
     Hai welcome to my app 
    </body> 
</html> 
+0

@homen ...嘗試使用您的代碼..仍然沒有重定向按鈕單擊.. – Jenz

+0

您是否只嘗試過此代碼?是否有其他代碼? – Homen

+0

我試着用你的代碼替換我的代碼。我也嘗試在按鈕點擊函數中添加'window.location'。這也沒有奏效.. – Jenz

1

您需要包括科爾多瓦在您的應用程序

,並嘗試這種之一,也是

document.addEventListener("deviceready", function(){ 
     alert("Device ready Fire"); 
},true); 
+0

@ RAj ..我得到了警報..但仍然沒有重定向到谷歌頁面。 – Jenz