Home > Web Front-end > H5 Tutorial > phonegap listens for other events after the deviceready event is triggered

phonegap listens for other events after the deviceready event is triggered

Y2J
Release: 2017-05-20 13:46:51
Original
2030 people have browsed it

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>
Copy after login

[Related recommendations]

1. HTML5 Free Video Tutorial

2. Detailed explanation of the example that realizes page jump and can pass value

3. Detailed explanation of the processing method of IE8 being incompatible with rgba()

4. Detailed explanation of the code for phonegap to complete the contact search function

5. Detailed explanation of the code for phonegap to complete the function of cloning and deleting contacts

The above is the detailed content of phonegap listens for other events after the deviceready event is triggered. 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