用hbuilder做手机app,在manifest.json的入口页面直接输入我的网址,生成app以后。按返回键直接退出app,我现在想按返回键返回上一页怎么设置啊?求大家不吝赐教
- 发布:2015-06-18 08:54
- 更新:2019-04-08 16:35
- 阅读:9838
Danny - QQ125904483
看在头像的份上我告诉你把,看看这个:
http://www.dcloud.io/docs/api/zh_cn/webview.shtml#plus.webview.WebviewObject.back
1.获得WebviewObject对象,点击返回的时候调用wobj.back()实现返回;
2.每次点击返回时wobj.canBack( queryCallback );判断是否已经是第一页,如果是,则提示是否退出应用程序,如果否则执行第一步的返回。
-
我是菜鸟 (作者)
不明白啊,是在index.html里面添加示例代码吗?怎么不起作用,能再指点一下吗,谢谢!
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript">
// H5 plus事件处理
function plusReady(){
// 获取所有Webview窗口
var wvs=plus.webview.all();
for(var i=0;i<wvs.length;i++){
console.log("webview"+i+": "+wvs[i].getURL());
}
}
if(window.plus){
plusReady();
}else{
document.addEventListener("plusready",plusReady,false);
}
</script>
<script type="text/javascript">
var embed=null;
// H5 plus事件处理
function plusReady(){
embed=plus.webview.create("http://weibo.com/dhnetwork","",{top:"46px",bottom:"0px"});
plus.webview.currentWebview().append( embed );
}
if(window.plus){
plusReady();
}else{
document.addEventListener("plusready",plusReady,false);
}
// 返回上次页面
function goBack() {
embed.back();
}
// 前进到上次页面
function goForward() {
embed.forward();
}
</script>
<script type="text/javascript">
var embed=null;
// H5 plus事件处理
function plusReady(){
embed=plus.webview.create("http://weibo.com/dhnetwork","",{top:"46px",bottom:"0px"});
plus.webview.currentWebview().append( embed );
}
if(window.plus){
plusReady();
}else{
document.addEventListener("plusready",plusReady,false);
}
// 是否可后退
function canBack() {
embed.canBack( function(e){
console.log( "是否可返回:"+e.canBack );
});
}
</script>
</head>
<body>
获取所有Webview窗口
后退到上次加载的页面
<button onclick="goBack()">Back</button>
<button onclick="goForward()">Forward</button>
查询Webview窗口是否可后退
<button onclick="canBack()">canBack</button>
</body>
</html>
2015-06-18 12:31
>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title></title>
<script src="js/mui.min.js"></script>
<link href="css/mui.min.css" rel="stylesheet" />
<script type="text/javascript">
mui.init();
</script>
</head>
<body>
<button id="btnBack" >Back</button>
<button id="btnFor"> Forward</button>
<script>
mui.plusReady(function() {
var win = plus.webview.create('http://weibo.com/dhnetwork', 'mywin', {
top: "44px",
bottom: "0px"
});
//创建子窗口
plus.webview.currentWebview().append(win);
});
mui.back = function() {
var mywin = plus.webview.getWebviewById('mywin');
mywin.canBack(function(e) {
if (e.canBack) {
mywin.back();
} else {
mui.confirm('确定退出应用?', '提示', ['确定', '取消'], function(e) {
if (e.index === 0) {
plus.runtime.quit();
}
});
}
});
};
document.getElementById("btnBack").addEventListener("tap",function(){
var mywin = plus.webview.getWebviewById('mywin');
mywin.canBack(function(e) {
if (e.canBack) {
mywin.back();
} else {
mui.confirm('确定退出应用?', '提示', ['确定', '取消'], function(e) {
if (e.index === 0) {
plus.runtime.quit();
}
});
}
});
});
document.getElementById("btnFor").addEventListener("tap",function(){
var mywin = plus.webview.getWebviewById('mywin');
mywin.canForward(function(e) {
if (e.canForward){
mywin.forward();
}
});
});
</script>
</body>
</html>
算了,好人做到底吧
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title></title>
<script src="js/mui.min.js"></script>
<link href="css/mui.min.css" rel="stylesheet" />
<script type="text/javascript">
mui.init();
</script>
</head>
<body>
<button id="btnBack" >Back</button>
<button id="btnFor"> Forward</button>
<script>
mui.plusReady(function() {
var win = plus.webview.create('http://weibo.com/dhnetwork', 'mywin', {
top: "44px",
bottom: "0px"
});
//创建子窗口
plus.webview.currentWebview().append(win);
});
mui.back = function() {
var mywin = plus.webview.getWebviewById('mywin');
mywin.canBack(function(e) {
if (e.canBack) {
mywin.back();
} else {
mui.confirm('确定退出应用?', '提示', ['确定', '取消'], function(e) {
if (e.index === 0) {
plus.runtime.quit();
}
});
}
});
};
document.getElementById("btnBack").addEventListener("tap",function(){
var mywin = plus.webview.getWebviewById('mywin');
mywin.canBack(function(e) {
if (e.canBack) {
mywin.back();
} else {
mui.confirm('确定退出应用?', '提示', ['确定', '取消'], function(e) {
if (e.index === 0) {
plus.runtime.quit();
}
});
}
});
});
document.getElementById("btnFor").addEventListener("tap",function(){
var mywin = plus.webview.getWebviewById('mywin');
mywin.canForward(function(e) {
if (e.canForward){
mywin.forward();
}
});
});
</script>
</body>
</html>
我是菜鸟 (作者)
在manifest.json文件里面可以直接写吗?我对这个不懂啊,谢谢!
2015-06-18 09:16