Home > Web Front-end > H5 Tutorial > Summary of common events in phonegap

Summary of common events in phonegap

php中世界最好的语言
Release: 2018-03-26 15:32:41
Original
1577 people have browsed it

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>
Copy after login
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website !

Recommended reading:

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template