4***@qq.com
4***@qq.com
  • 发布:2017-08-31 13:12
  • 更新:2018-09-27 23:04
  • 阅读:5597

关于webview嵌入web项目打包APP,android物理返回按钮的处理

分类:HTML5+
  1. 首先我项目中没有用到mui.js,只是壳打包web项目和调用了h5+的支付
  2. 注册h5+的返回按钮事件 plus.key.addEventListener('backbutton',backListener,false);
  3. 事件中判断是不是在首页,然后进行处理
  4. w是创建的webview
  5. 目前实现到首页提示再按一次退出程序,和一级页面的返回,二级页面会只能返回一级,谁有好的解决方案望探讨

var first=null;
function backListener(){
//首次按键,提示‘再按一次退出应用’
if(w!=null){
var u=w.getURL();
if(u.lastIndexOf("welcome/index.htm")>0||u.lastIndexOf("ziyuan/index.htm")>0||u.lastIndexOf("xuqiu/index.htm")>0||u.lastIndexOf("paimai/index.htm")>0){
if (!first) {
console.log(u);
first = new Date().getTime();
plus.nativeUI.toast('再按一次退出程序');
setTimeout(function() {
first = null;
}, 1000);
} else {
if (new Date().getTime() - first < 1000) {
plus.runtime.quit();
}
}
}else{
w.canBack(function(e){
if(e.canBack){
w.back();
}else{
w.loadURL(weburl+'/welcome/index.htm');
}
});
w.canForward(function(e){
if(e.canForward){
w.forward();
}
});
}
}
}

0 关注 分享

要回复文章请先登录注册

村长3456

村长3456

请问,直接转的web app怎么引入js。
2018-09-27 23:04
雪之梦技术驿站

雪之梦技术驿站

可以的,最近才发现如果不用mui框架,一些常见的js操作是多么无力,所以最好还是引入mui.js吧
2017-08-31 13:42