Home > Article > Web Front-end > Common phonegap events you must know
The editor below will bring you a summary of common phonegap events (a must-read article). The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor and 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>
The above is the detailed content of Common phonegap events you must know. For more information, please follow other related articles on the PHP Chinese website!