用HB打包一个手机网站,,不能实现"返回上一页",按手机的返回键系统就关闭了。没有任何提示。我该如何处理能实现”返回上一页“的功能,谢谢!
若飞一狼
- 发布:2015-06-03 15:38
- 更新:2015-06-04 14:03
- 阅读:3732
用HB打包一个手机网站,,不能实现"返回上一页",按手机的返回键系统就关闭了。
分类:HBuilder
你需要先定义物理返回键
//取消浏览器的所有事件,使得active的样式在手机上正常生效
document.addEventListener('touchstart',function(){
return false;
},true);
// 禁止选择
document.oncontextmenu=function(){
return false;
};
// H5 plus事件处理
var as='slide-in-right',at=200;// 默认动画时间
// 扩展API准备完成后要执行的操作
function plusReady(){
// 隐藏滚动条
plus.webview.currentWebview().setStyle({scrollIndicator:'none'});
// Android处理返回键
var pageUrl=window.location.href;
plus.key.addEventListener('backbutton',function(){
//判断是否返回到首页,是->退出,否则返回上一页
if(pageUrl.indexOf('index')==-1){
history.back();
}else{
if(confirm('确认退出?')){
plus.runtime.quit();
}
}
},false);
}
//扩展API是否准备好,如果没有则监听“plusready"事件
if(window.plus){
plusReady();
}else{
document.addEventListener('plusready',plusReady,false);
}
上面的代码单独放在一个js文件,然后每个页面都引入,就可以实现了
大师兄
indexOf里面是入口页面,可自行修改
2015-06-04 11:31