Events---cordova事件

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/
Events
android blackberry10 ios Windows Phone 8 Windows
deviceready          
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触发立马执行
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Cordova 是一个用于创建移动应用程序的开源平台,它结合了HTML,CSS和JavaScript,可以帮助开发人员构建跨平台的移动应用程序。 Cordova 的版本号可以通过在终端或命令提示符中运行 "cordova --v" 命令来查看。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [cordova-chartboost-plugin:Chartboost 插件 Cordova](https://download.csdn.net/download/weixin_42106299/19396455)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [百度地图定位Cordova插件cordova-plugin-baidumaplocation.zip](https://download.csdn.net/download/weixin_39840387/11386209)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [cordova-plugin-local-notifications:科尔多瓦本地通知插件](https://download.csdn.net/download/weixin_42098104/15484674)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值