web-view打开外部 网站
2020-03-13 本文已影响0人
荼蘼toome
尝试版本一 uni-app
返回按钮直接退出
将page.json中的导航去掉
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "uni-app",
"app-plus":{
"titleNView":false
}
}
<template>
<!-- <view>454545</view> -->
<web-view :webview-styles="{height: '100vh', width: '100vw'}" :src="src"></web-view>
</template>
<script>
export default {
data() {
return {
src: 'https://www.....cn/mobile/'
}
},
onShow: function() {
const src = plus.runtime.arguments || '';
this.src = (src.match(/\/\/(https:\/\/.+)/) || [])[1] || this.src;
// 追加http路由
console.log(this.src);
},
// 下拉效果
//onPullDownRefresh() {
// console.log("refresh")
//},
// 正式版使用 返回,没有办法退出了=-=
// onBackPress(options) {
// const currentWebview = this.$mp.page.$getAppWebview();
// const wv = currentWebview.children()[0];
// wv.evalJS('history.length')
// console.log(wv.evalJS('history.length'))
// // if(){
// // }
// wv.evalJS('history.back()')
// return true;
// },
// 测试版一 监听页面返回
// onBackPress(options) {
// //右上角的
// console.log(' 00',options)
// const currentWebview = this.$mp.page.$getAppWebview();
// if (currentWebview) {
// let child = currentWebview.children();
// for (let i = 0; i < child.length; i++) {
// currentWebview.remove(child[i]);
// }
// }
// return false;
// }
}
</script>
<style>
</style>
有煤油可以help 么的
方案二 wap2app
使用sitemap.json文件修改
首页底部的导航栏,会留有历史记录,返回的时候,页面不友好
~不行 返回按钮 ~
{
"global": {
"webviewParameter": {
"titleNView": {
"autoBackButton": true,
"backgroundColor": "#f7f7f7", //导航栏背景色
"titleColor": "#000000", //标题颜色
"titleSize": "17px"
},
"statusbar": {
//系统状态栏样式(前景色)
"style": "dark"
},
"appendCss": "",
"appendJs": ""
},
// 监听返回按钮,是否返回上一级
"easyConfig": {
"back": {
"history": false
},
"quit": {
"toast": {
"showFeedback": false //不显示“反馈意见”链接,默认为true
}
}
}
},
"pages": [{
"webviewId": "__W2A__www.hjrqc.cn", //首页
"matchUrls": [{
"href": "https://www.hjrqc.cn/mobile"
}, {
"href": "https://www.hjrqc.cn/mobile/"
}],
"webviewParameter": {
"titleNView": false,
"statusbar": {
//状态条背景色,
//首页不使用原生导航条,颜色值建议和global->webviewParameter->titleNView->backgroundColor颜色值保持一致
//若首页启用了原生导航条,则建议将首页的statusbar配置为false,这样状态条可以和原生导航条背景色保持一致;
"background": "#f7f7f7"
}
},
// 监听返回按钮,是否返回上一级
"easyConfig": {
"back": {
"history": false
},
"quit": {
"toast": {
"showFeedback": false //不显示“反馈意见”链接,默认为true
}
}
}
},
//未适配的公共页面,可拦截原生下载和头部导航栏, 注:通配符的规则+放在最后一个节点才能达到适配所有未适配的公共页面效果,适配规则优先级为自上而下查找匹配规则 -效果-没有内部的导航栏
{
"webviewId": "common",
"matchUrls": [{
"hostname": "R:.*",
"pathname": "R:.*"
}],
"webviewParameter": {
"titleNView": false,
"statusbar": {
"background": "#f7f7f7"
}
},
// 监听返回按钮,是否返回上一级
"easyConfig": {
"back": {
"history": false
},
"quit": {
"toast": {
"showFeedback": false //不显示“反馈意见”链接,默认为true
}
}
}
}
]
}