Events---cordova事件

来源:互联网 发布:黑暗网络泄露图片 编辑:程序博客网 时间:2024/05/22 23:22

There are various events provided by cordova to be used by the application. The application code could add listeners for these events. For example:

cordava提供事件:上代码

HTML File

<!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" src="example.js"></script>    </head>    <body onload="onLoad()">    </body></html>
这是html调用了onload

既然说事件  可能有回调,写在了js里面

JS File

// example.js file// Wait for device API libraries to load//function onLoad() {    document.addEventListener("deviceready", onDeviceReady, false);}// device APIs are available//function onDeviceReady() {    document.addEventListener("pause", onPause, false);    document.addEventListener("resume", onResume, false);    document.addEventListener("menubutton", onMenuKeyDown, false);    // Add similar listeners for other events}function onPause() {    // Handle the pause event}function onResume() {    // Handle the resume event}function onMenuKeyDown() {    // Handle the menubutton event}// Add similar event handlers for other events
这么多函数好乱,接着看

onDeviceReady

Note: Applications typically should use document.addEventListener to attach an event listener once the deviceready

addEventListener  加上监听

The following table lists the cordova events and the supported platforms:事件支持机子:看来有些不支持回调啊,有哪些事件不支持那些机子呢:


Supported Platforms/
Eventsandroidblackberry10iosWindows Phone 8Windowsdeviceready     pause     resume     backbutton     menubutton     searchbutton     startcallbutton     endcallbutton     volumedownbutton     volumeupbutton     activated     

deviceready


The deviceready event fires when Cordova is fully loaded. This event is essential to any application. It signals that Cordova's device APIs have loaded and are ready to access.

deviceready 是最早的一个监听,Cordova 一旦加载完毕就出发此回调。标志Cordova api完全加载,可以利用。刨出来的坑终于可以拉屎了。

Cordova consists of two code bases: native and JavaScript. While the native code loads, a custom loading image displays. However, JavaScript only loads once the DOM loads. This means the web app may potentially call a Cordova JavaScript function before the corresponding native code becomes available.

Cordova :js   native哪个会先调用呢,js方法可以在native调用回来之前调用。


The deviceready event fires once Cordova has fully loaded. Once the event fires, you can safely make calls to Cordova APIs. Applications typically attach an event listener with document.addEventListener once the HTML document's DOM has loaded.

Dom一旦加载  就可以用deviceready 起作用了

The deviceready event behaves somewhat differently from others. Any event handler registered after the devicereadyevent fires has its callback function called immediately.

此句强调了deviceready 的江湖地位,一旦出发了deviceready 就立马执行他的回调实现

一瞥:

Quick Example

document.addEventListener("deviceready", onDeviceReady, false);function onDeviceReady() {    // Now safe to use device API deviceready触发立马执行}




原创粉丝点击