太阳光
太阳光
  • 发布:2015-03-15 21:39
  • 更新:2015-03-17 15:32
  • 阅读:2027

Hello-mui右上角关于链接失败问题!

分类:MUI

Hello-mui模板中有个右上角关于图标,是examples/info.html“关于”的链接页面。当其他任意链接点击出现链接失败后出现"we're sorry..."界面,当点击"Close"按钮后就再也点不开“关于”这个页面(同时Back按钮也不是正确返回,这应该跟自身的webview有关),同时错误链接地址也不会提醒了,只显示“加载中...”界面。大概错误在index.html 146行template失败造成,希望指点迷津。

2015-03-15 21:39 负责人:无 分享
已邀请:
DCloud_UNI_FXY

DCloud_UNI_FXY

出现这个问题是因为你点击close后,会把当前webview给彻底close掉。导致后续的其他页面无法复用该webview了。

如果你的业务会存在这种出现we're sorry的页面,建议可以自己自定义error页面,自己实现close的逻辑,如果是模板页面,那就hide掉,而不是close掉。

太阳光

太阳光 (作者)

谢谢。
其实也就是说要么在错误页中禁止出现关闭按钮,或者要判断webview是否已经被close掉,需要重建。能否举例重建这种脚本?

DCloud_UNI_FXY

DCloud_UNI_FXY

你可以plus.webview.getWebviewById()判断一下是否还存在。

又或者。自己重写错误页面。在manifest.json中配置你自己的错误页面。

<!DOCTYPE html>  
<html>  
<head>  
    <meta charset="utf-8"/>  
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>  
    <meta name="HandheldFriendly" content="true"/>  
    <meta name="MobileOptimized" content="320"/>  
    <title>Error</title>  
    <script type="text/javascript">  
// H5 plus事件处理  
var ws=null;  
function plusReady(){  
    // Android处理返回键  
    plus.key.addEventListener('backbutton',function(){  
        (history.length==1)&&ws.close();  
        var c=setTimeout(function(){  
            ws.close();  
        },1000);  
        window.onbeforeunload=function(){  
            clearTimeout(c);  
        }  
        history.go(-2);  
    },false);  
    ws=plus.webview.currentWebview();  
}  
if(window.plus){  
    plusReady();  
}else{  
    document.addEventListener('plusready',plusReady,false);  
}  
document.addEventListener('touchstart',function(){  
    return false;  
},true);  
// 禁止选择  
document.oncontextmenu=function(){  
    return false;  
};  
    </script>  
    <style>  
*{  
    -webkit-user-select: none;  
}  
html,body{  
    margin: 0px;  
    padding: 0px;  
    width: 100%;  
    height: 100%;  
    text-align: center;  
    -webkit-touch-callout:none;  
    -webkit-tap-highlight-color:rgba(0,0,0,0);  
}  
.button{  
    width: 50%;  
    font-size: 18px;  
    font-weight: normal;  
    text-decoration: none;  
    text-align: center;  
    padding: .5em 0em;  
    margin: .5em auto;  
    color: #333333;  
    background-color: #EEEEEE;  
    border: 1px solid #CCCCCC;  
    -webkit-border-radius: 5px;  
    border-radius: 5px;  
}  
.button:active{  
    background-color: #CCCCCC;  
}  
    </style>  
</head>  
<body>  
    <div style="width:100%;height:20%;"></div>  
    <svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 512 512" style="height:20%;">   
    <g id="icomoon-ignore">  
        <line stroke-width="1" x1="" y1="" x2="" y2="" stroke="#449FDB" opacity=""></line>  
    </g>  
    <path d="M256 0c-141.385 0-256 114.615-256 256s114.615 256 256 256 256-114.615 256-256-114.615-256-256-256zM352 128c17.673 0 32 14.327 32 32s-14.327 32-32 32-32-14.327-32-32 14.327-32 32-32zM160 128c17.673 0 32 14.327 32 32s-14.327 32-32 32-32-14.327-32-32 14.327-32 32-32zM352.049 390.37c-19.587-32.574-55.272-54.37-96.049-54.37s-76.462 21.796-96.049 54.37l-41.164-24.698c27.98-46.535 78.958-77.672 137.213-77.672s109.232 31.137 137.213 77.672l-41.164 24.698z" fill="#666666"></path>  
    </svg>  
    <p style="font-size:18px;font-weight:bolder;">We're sorry ...</p>  
    <!--<div class="button" onclick="history.back()">Retry</div>-->  
<!--此处需要你自己识别是close还是hide-->  
    <div class="button" onclick="if(history.length == 1){ws.close();}else{ws.back();ws.back();}">Back</div>  
<!--此处需要你自己识别是close还是hide-->  
    <div class="button" onclick="ws.close()">Close</div>  
</body>  
</html>  

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