admin管理员组文章数量:1356585
index.html
<script>
function onDeviceReady() {
alert("onDeviceReady");
var options = {frequency: 500};
watchId = navigator.accelerometer.watchAcceleration(onSuccess, onFailure, options);
}
document.addEventListener("deviceready", onDeviceReady, false);
</script>
Phonegap 3.3.3 device ready handler is not being called.
index.html
<script>
function onDeviceReady() {
alert("onDeviceReady");
var options = {frequency: 500};
watchId = navigator.accelerometer.watchAcceleration(onSuccess, onFailure, options);
}
document.addEventListener("deviceready", onDeviceReady, false);
</script>
Phonegap 3.3.3 device ready handler is not being called.
Share Improve this question asked Jan 3, 2014 at 19:20 user812954user812954 4,4013 gold badges21 silver badges18 bronze badges 2- 1 Looks good to me. When you say Phonegap 3.3.3, do you mean Cordova 3.3.0 or are you using an edge version. I assume you are trying this on the device/simulator and not through the web browser. deviceready, will not fire in a browser. – Dustin Simpson Commented Jan 3, 2014 at 20:50
- oops, 3.3.3 was a typo, i was using Cordova 3.3.0 – user812954 Commented Jan 8, 2014 at 22:28
3 Answers
Reset to default 4Make sure you have included the phonegap.js (or cordova.js) script in your html. Otherwise your code is fine. Try menting everything else except the alert in onDeviceReady() in case the issue still persists.
Try posting your index.html with the question if there are still issues.
It is a best practice to set your event listener in a function after the document finishes loading. Try something like this:
<body onload="onLoad()">
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
or with jquery:
$(document).ready(function() {
document.addEventListener("deviceready", onDeviceReady, false);
});
remove app.initialize() from the script (that messes up the event handler)
本文标签: javascriptdeviceready handler not being called ios phonegap 333Stack Overflow
版权声明:本文标题:javascript - deviceready handler not being called ios phonegap 3.3.3 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744066761a2585143.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论