uniapp中webview支持history.back的方法
发表于:2022-02-15 13:35:11浏览:856次
在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>
推荐文章
- ES6 用反引号(`)标识模板字符串详解
- 简单几行代码实现JS复制文字到剪切板的功能,兼容IE浏览器
- 谷歌发布Flutter 3,增加对macOS和Linux 应用的支持
- VUE新一代状态管理插件Pinia
- 谷歌发布全新操作系统chromeOS Flex首个稳定版,可用于 PC 和 Mac
- 微信H5版使用php Ffmpeg将微信录音amr转mp3
- ThinkPHP发布安全更新版本(V6.1.0/V6.0.14),移除对think-filesystem库的依赖
- 用ECharts的getDataURL方法自动下载Chart图到服务器
- 尝鲜,Windows 11默认壁纸下载,4K分辨率哦
- 新一代的CRM系统的操作权限和数据权限的设计