paradox
paradox
  • 发布:2015-03-07 01:06
  • 更新:2015-03-07 01:18
  • 阅读:4273

mui.toast无法显示,求解(附代码)

分类:MUI
<!DOCTYPE html>  
<html>  

    <head>  
        <meta charset="utf-8">  
        <title>Hello MUI</title>  
        <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">  
        <meta name="apple-mobile-web-app-capable" content="yes">  
        <meta name="apple-mobile-web-app-status-bar-style" content="black">  
        <script src="js/mui.min.js"></script>  
        <script src="js/update.js" type="text/javascript" charset="utf-8"></script>  
        <link rel="stylesheet" href="css/mui.min.css">  
    </head>   

    <body>  

        <header class="mui-bar mui-bar-nav">  
            <a class="mui-icon mui-icon-bars mui-pull-left"></a>  
            <h1 class="mui-title" style="color: darkorange;">test</h1>  
        </header>  

        <nav class="mui-bar mui-bar-tab">  
            <a class="mui-tab-item " id="refresh">  
                <span class="mui-icon mui-icon-refreshempty"></span>  
                <span class="mui-tab-label">刷新</span>  
            </a>  
            <a class="mui-tab-item  " id="back">  
                <span class="mui-icon mui-icon-back"></span>  
                <span class="mui-tab-label">后退</span>  
            </a>  
            <a class="mui-tab-item  " id="stop">  
                <span class="mui-icon mui-icon-closeempty"></span>  
                <span class="mui-tab-label">停止</span>  
            </a>  
            <a class="mui-tab-item  " id="forward">  
                <span class="mui-icon mui-icon-forward"></span>  
                <span class="mui-tab-label">前进</span>  
            </a>  
            <a class="mui-tab-item " id="home">  
                <span class="mui-icon mui-icon-home"></span>  
                <span class="mui-tab-label">首页</span>  
            </a>  
        </nav>  

        <script>  
            var menu = null,  
                main = null;  
            mui.init();  
            mui.plusReady(function() {  
                if (mui.os.android) {  
                    plus.screen.lockOrientation("portrait-primary");  
                }    
                main = plus.webview.currentWebview();  

                content = plus.webview.create('http://www.baidu.com','content',{  
                    top: '49px',  
                    bottom: '55px',  
                    bounce: 'vertical'  
                });  
                //content.show();  
                main.append(content);  

                var eventId;  
                //刷新    
                document.getElementById("refresh").addEventListener("tap",function(){  
                    eventId="refresh";  
                    content.reload();  
                })  
                //返回键  
                document.getElementById("back").addEventListener("tap",function(){  
                    eventId="back";  
                    thisid=this;  
                    content.canBack(function(e){  
                        if (e.canBack) {  
                            content.back();  
                        }  
                        else{  
                            setTimeout(function(){  
                                thisid.className="mui-tab-item";  
                            },150);  
                        }  
                    });  
                })   

                //停止  
                document.getElementById("stop").addEventListener("tap",function(){  
                    content.stop();  
                    thisid=this;  
                    setTimeout(function(){  
                        thisid.className="mui-tab-item";  
                    },150);  
                })  
                //前进  
                document.getElementById("forward").addEventListener("tap",function(){  
                    eventId="forward";  
                    thisid=this;  
                    content.canForward(function(e){  
                        if (e.canForward) {  
                            content.forward();  
                        }  
                        else{  
                            setTimeout(function(){  
                                thisid.className="mui-tab-item";  
                            },150);  
                        }  
                    });  
                })  

                //首页  
                document.getElementById("home").addEventListener("tap",function(){  
                    eventId="home";  
                    content.loadURL("content.html");  
                })  

                content.addEventListener('loaded',function(){  
                    window.showFullProcessBar=true;  
                    if (eventId) {  
                        document.getElementById(eventId).className="mui-tab-item";  
                    }  
                    else{  
                        document.getElementById("stop").className="mui-tab-item";  
                    }  
                    eventId=null;  
                });   

                content.addEventListener('loading',function(e){  
                    if (!eventId) {  
                        document.getElementById("stop").className="mui-tab-item mui-active";  
                    }  
                });      
            });  

            var first = null;  
            mui.back = function() {  

                //首次按键,提示‘再按一次退出应用’  
                if (!first) {  
                    mui.toast('显示不出来?');   
                    alert("dddd");  
                    first = new Date().getTime();  
                    setTimeout(function() {  
                        first = null;  
                    }, 1500);  
                } else {  
                    if (new Date().getTime() - first < 1500) {  
                        plus.runtime.quit();  
                    }  
                }  

            };  

        </script>  

    </body>  

</html>

点击安卓返回按钮,toast无法显示出来,有时候点击百度页面中的链接后再点击安卓返回按钮,连alert("dddd")也无法显示,请教原因以及解决方法。谢谢!

2015-03-07 01:06 负责人:无 分享
已邀请:
paradox

paradox (作者)

如果把:

content = plus.webview.create('http://www.baidu.com','content',{  
                    top: '49px',  
                    bottom: '55px',  
                    bounce: 'vertical'  
                });

改成:

content = plus.webview.create('content.html','content',{  
                    top: '49px',  
                    bottom: '55px',  
                    bounce: 'vertical'  
                });//content.html是自己的一个页面

从content页面进入百度首页再点击百度链接后,点击安卓返回键就没有任何反应了,alert不出现,也无法退出。

该问题目前已经被锁定, 无法添加新回复