This time I will bring you a summary of the common events of phonegap. What are the precautions for using common events of phonegap. The following is a practical case, let’s take a look.
In any PhoneGap project, you should first listen to the deviceready event. Event triggering indicates that the DOM has been loaded and PhoneGapAPI has been loaded. At this time, other events can be detected or other content can be processed.Other events:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>PhoneGap resume Example</title> <script type="text/javascript" charset="UTF-8" src="cordova.js"></script> <script type="text/javascript" charset="UTF-8"> document.addEventListener("deviceready",onDeviceReady,false); function onDeviceReady(){ //注册事件侦听器 document.addEventListener("resume",onResume,false); document.addEventListener("pause",onPause,false); document.addEventListener("menubutton",onMenuButton,false); document.addEventListener("backbutton",onBackButton,false); document.addEventListener("searchbutton",onSearchButton,false); document.addEventListener("online",isOnline,false); document.addEventListener("offline",isOffline,false); } //处理恢复事件 function onResume(){ alert("页面恢复"); } //处理暂停事件 function onPause(){ alert("页面暂停"); } //处理菜单按钮 function onMenuButton(){ alert("点击菜单按钮"); } //处理返回按钮 function onBackButton(){ alert("点击返回按钮"); } //处理搜索按钮 function onSearchButton(){ alert("点击搜索按钮"); } //处理在线事件(连接到Internet) function isOnline(){ alert("网络连接"); } //处理离线事件(断开Internet连接) function isOffline(){ alert("网络断开); } </script> </head> <body> </body> </html>
Detailed explanation of phonegap operation database
Detailed explanation of phonegap local storage
The above is the detailed content of Summary of common events in phonegap. For more information, please follow other related articles on the PHP Chinese website!