Reputation: 1
Has anyone experienced an issue with javascript function not working on Phonegap/iOS 4.3? I've tested my javascript in my Safari browser and it works. But when I try it in on the iOS simulator or my iPod touch it doesn't work.
Here's my code: in head:
function sayingHi(){
alert("This is saying hi!");
}
HTML:
<button onclick="sayingHi();">Saying hi</button>
If I create javascript in the it works fine: onclick="alert('Saying hi!');"
Upvotes: 0
Views: 1768
Reputation: 9615
In PhoneGap you can only access the PhoneGap API after it has loaded. This is indicated by the "deviceready" event being fired. If you try to do anything with the PhoneGap API (like an alert) before that happens, it will not work.
Try this:
<script type="text/javascript">
function init() {
document.addEventListener("deviceready", function(){
navigator.notification.alert(device.phonegap);
});
}
</script>
</head>
<body onload="init()">
Notice also that I am using the notification API in PhoneGap. This is a better way to create an alert because it is more customizable.
Reference: http://docs.phonegap.com/en/1.1.0/phonegap_notification_notification.md.html
Upvotes: 1