Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phonegap doesn't show alert

why phonegap doesn't show alert notification ? (running on iPhone 5.1.1 , phonegap phonegap-2.1.0-0-g26d211b, mountain lion 10.8.2, xcode 4.4.1)

<html>
<head>
<link rel="stylesheet" href="themes/css/apple.css" title="jQTouch">
<script src="src/lib/zepto.min.js" type="text/javascript" charset="utf-8"></script>
<script src="cordova-2.1.0.js" type="text/javascript" charset="utf-8"></script>
<script src="src/jqtouch.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
    $(document).ready(function(){
     try
     {
        navigator.notification.alert('Hello', ok, 'Title', 'Button!');  
     }
     catch(e)
     {
        alert("doesn't support!!");
     }
    }
    function ok() {}
</script>
</head>
</html>
like image 335
Pharaz Fadaei Avatar asked Feb 27 '26 03:02

Pharaz Fadaei


1 Answers

Because you are trying to show an alert before phonegap/cordova framework is loaded.

$(document).ready(function(){ is not going to help you here, you must use this event to check if phonegap is successfully loaded:

document.addEventListener("deviceReady", deviceReady, false);

function deviceReady() {
    // Now safe to use the PhoneGap API
}

More about this event: http://docs.phonegap.com/en/1.0.0/phonegap_events_events.md.html

PhoneGap consists of two code bases: native and JavaScript. While the native code is loading, a custom loading image is displayed. However, JavaScript is only loaded once the DOM loads. This means your web application could, potentially, call a PhoneGap JavaScript function before it is loaded.

like image 137
Gajotres Avatar answered Feb 28 '26 15:02

Gajotres



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!