2012-09-18 53 views
0

我是新來phonegap.In我的申請,我想顯示alerts.For,我已經使用下面的代碼,navigator.notification.alert()在cordova-2.0.0.js中不起作用?

navigator.notification.alert("PhoneGap is working"); 

但它不是working.My總HTML代碼,

<html> 
    <head> 
    <script type="text/javascript" charset="utf-8" src="js/cordova-2.0.0.js"></script> 
    <script> 

     function inti() 
    { 
    alert("inti"); 
    document.addEventListener("deviceready", onDeviceReady, true); 

    } 
    function onDeviceReady() { 
      alert("on device ready!!!!"); 
    navigator.notification.alert("PhoneGap is working"); 
    } 
    </script> 
    </head> 
    <body onload="inti()"> 
    <p id="demo">System date</p> 
    <input type="button" onclick="noti()" value="Date" /> 
    </body> 
</html> 

我得到了Cannot call method 'alert' of undefined i got this error。任何人都可以指導我解決這個問題。在此先感謝.....

回答

4

您忘了添加cordova.js。嘗試添加這個。

<script type="text/javascript" charset="utf-8" src="js/cordova-2.0.0.js"></script>

還添加

document.addEventListener("deviceready", onDeviceReady, true);以上onDeviceReady()功能。

+0

不能調用未定義的方法'alert'我得到了這個錯誤 –

+0

你應該有一個init()方法在onload上調用,然後在init()中爲「deviceready」註冊一個監聽器,然後在onDeviceReady()警報。 –

+0

我已經添加了你的建議。添加inti()方法onDeviceReady()不調用....我已經添加了我的完整代碼你建議請看看.... –

-1

navigator.notification.alert( 「是」, callBackFunctionB,//指定一個被稱爲 '標題' 功能, 「OK」 );

0

檢查您的Cordova Jar文件版本,並且您已寫入<script>。可能會有所不同。