美文网首页
安卓双击返回键退出软件监听

安卓双击返回键退出软件监听

作者: _YDS | 来源:发表于2017-09-17 16:30 被阅读0次
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css"/>
    <link rel="stylesheet" type="text/css" href="../css/zqb-login.css"/>
    <style>
        
    </style>
</head>
<body style="background:url(../image/log-bg.png) no-repeat; background-size: 100%; background-color: #fff;">
    <div id="title" class="aui-margin-t-15 aui-margin-b-15">
        ![](../image/log-title.png)
    </div>
    <div id="main"></div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript">
    apiready = function(){
        
        
        exitApp();
    };
    
    //两秒内连续按两次返回键,退出
    function exitApp(){
        var n = 0;
        var time1, time2;
        api.addEventListener({
            name: 'keyback'
        }, function(ret, err){
            if (n == 0) {
                time1 = new Date().getTime();
                n = 1;
                api.toast({msg:'再按一次返回键退出'});
            }else if(n==1){
                time2 = new Date().getTime();
                if (time2 - time1 < 2000) {
                    api.closeWidget({
                        id: 'A6923149075999',  //填写自己的id   
                        retData: {name:'closeWidget'},
                        silent:true                        
                    });
                }else{
                    n=1;
                    time1=time2;
                    api.toast({msg:'再按一次返回键退出'});
                }
            }
             
        });
    }
</script>
</html>

相关文章

网友评论

      本文标题:安卓双击返回键退出软件监听

      本文链接:https://www.haomeiwen.com/subject/abqmsxtx.html