在Phonegap中,我使用该代码获取设备就绪功能
function init() {
document.addEventListener("deviceready", onDeviceReady, true);
}
var onDeviceReady = function() {
~
};
但在cordova(Phonegap 3.0 over)中,此代码会导致错误。 我怎样才能获得Phonegap init功能?
谢谢。
答案 0 :(得分:0)
这是使用deviceready事件的常规方法:
document.addEventListener("deviceready",onDeviceReady,false);
// device APIs are available
//
function onDeviceReady() {
your function here
}
答案 1 :(得分:0)
以下是您的示例:
<!DOCTYPE html>
<html>
<head>
<title>Device Ready Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load //
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// device APIs are available //
function onDeviceReady() {
// Now safe to use device APIs
}
</script>
</head>
<body onload="onLoad()">
</body>
</html>
来自:http://cordova.apache.org/docs/en/3.5.0/cordova_events_events.md.html#Events