uniapp中webview支持history.back的方法
发表于:2022-02-15 13:35:11浏览:4693次
在uni-app中使用了webview之后, 由于项目完全由app内嵌h5完成, 所以无法控制app的物理返回键; 要实现这个功能,最主要的是完成应用与H5 的通讯问题。
<template>
<view></view>
</template>
<script>
export default {
data () {
return {
wv: null
}
},
onLoad() {
// #ifdef APP-PLUS
const url = '网址';
const wv = plus.webview.create("", "custom-webview", {
plusrequire: "none", //禁止远程网页使用plus的API,
'uni-app': 'none', //不加载uni-app渲染层框架
})
wv.loadURL(url);
const currentWebview = this.$scope.$getAppWebview();
currentWebview.append(wv);
this.wv = wv
// #endif
},
onBackPress() {
var _this = this;
_this.wv.canBack(function(e){
console.log(e);
if(e.canBack)
{
_this.wv.back()
}
else
{
uni.showModal({
'title':'确定要退出应用吗?',
success:function(e){
if(e.confirm)
{
plus.runtime.quit();
}
}
})
}
})
return true;
},
onNavigationBarButtonTap (e) {
uni.navigateBack()
}
}
</script>推荐文章
- Windows Terminal Preview 1.15 发布
- 前端报错:was loaded over HTTPS, but requested an insecure错误解决方案
- 90多款国内免费可商用的字体
- PHP8.5将于2025年11月20日正式发布,还在用PHP 5.6的老版本用户该何去何从?
- Layui 2.8.0 正式发布,她朴实归来了
- 支付宝已支持给微信QQ好友转账 微信支付宝互通何时能实现?
- 研发/技术总监(CTO)的日常工作都在做些什么?
- ThinkPHP6防止XSS攻击的方案
- PHP根据昵称或者姓名自动生成文字头像(图片)的方法
- 如何在gitee上提交Pull Request,给他人的项目贡献自己的代码

