Home  >  Article  >  Web Front-end  >  Summary of common events in phonegap (collection)

Summary of common events in phonegap (collection)

黄舟
黄舟Original
2017-05-21 14:38:221381browse

The following editor will bring you a summary of common events of phonegap (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 Summary of common events in phonegap (collection). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn