I am creating a simple phonegap based application using jQuery mobile.
Here is the Header of my HTML
<script src="scripts/jquery-1.8.2.min.js"></script>
<script src="scripts/jquery.mobile-1.1.1.min.js"></script>
<script src="scripts/jquery.jsonp-2.4.0.min.js"></script>
<script type="text/javascript" charset="utf-8" src="scripts/cordova-2.2.0.js"></script>
<script src="scripts/my.js"></script>
In the body after all my HTML code I have added
<script>
$(document).ready(function() {
navigator.notification.confirm('Do you want to quit',
function(){
if(button == "1"){
navigator.app.exitApp(); }
},
'QUIT TITLE',
'OK,Cancel'
);
</script>
I get the error
12-27 21:28:17.998: D/CordovaLog(17212): Uncaught TypeError: Cannot call method 'confirm' of undefined 12-27 21:28:17.998: D/CordovaLog(17212): file:///android_asset/www/app.html: Line 227 : Uncaught TypeError: Cannot call method 'confirm' of undefined
As you can see I have loaded all the necessary scripts, and I am calling the navigator.notification.confirm
inside $(document).ready
Not sure why I am getting this error. Please help.
I am creating a simple phonegap based application using jQuery mobile.
Here is the Header of my HTML
<script src="scripts/jquery-1.8.2.min.js"></script>
<script src="scripts/jquery.mobile-1.1.1.min.js"></script>
<script src="scripts/jquery.jsonp-2.4.0.min.js"></script>
<script type="text/javascript" charset="utf-8" src="scripts/cordova-2.2.0.js"></script>
<script src="scripts/my.js"></script>
In the body after all my HTML code I have added
<script>
$(document).ready(function() {
navigator.notification.confirm('Do you want to quit',
function(){
if(button == "1"){
navigator.app.exitApp(); }
},
'QUIT TITLE',
'OK,Cancel'
);
</script>
I get the error
12-27 21:28:17.998: D/CordovaLog(17212): Uncaught TypeError: Cannot call method 'confirm' of undefined 12-27 21:28:17.998: D/CordovaLog(17212): file:///android_asset/www/app.html: Line 227 : Uncaught TypeError: Cannot call method 'confirm' of undefined
As you can see I have loaded all the necessary scripts, and I am calling the navigator.notification.confirm
inside $(document).ready
Not sure why I am getting this error. Please help.
Share Improve this question edited Jun 12, 2015 at 11:14 Gajotres 57.3k16 gold badges105 silver badges131 bronze badges asked Dec 27, 2012 at 16:18 RajeshRajesh 1132 silver badges6 bronze badges 1- are you calling it when the device is ready? – freejosh Commented Dec 27, 2012 at 16:21
1 Answer
Reset to default 4First your code inside script tag is not closed properly.
You are trying to use a Phonegap library before is is successfully loaded. $(document).ready(function() { should not be used with jQuery mobile (you will find more about this in a bottom link), nor it will tell you if phonegap libraries are loaded.
Your code should be initialized like this:
document.addEventListener("deviceReady", deviceReady, false);
function deviceReady() {
navigator.notification.confirm('Do you want to quit',
function(){
if(button == "1"){
navigator.app.exitApp();
}
},
'QUIT TITLE',
'OK,Cancel'
);
}
You can find more about this here: https://stackoverflow./a/14010308/1848600 and here: http://docs.phonegap./en/1.0.0/phonegap_events_events.md.html
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745258585a4619104.html
评论列表(0条)