在全局定义方法:index.html
<script> var toUrl = 'http://api-test.995120.cn/healthh5/'; function controlBackButton() { location.href = toUrl } </script>在页面初始化调用
// 第一步: if (window.history && window.history.pushState) { history.pushState(null, null, document.URL); window.addEventListener("popstate", this.goBack, false); }页面销毁时间,调用
destroyed() { // 第二步: window.removeEventListener("popstate", this.goBack, false); },方法定义
// 第三步 goBack() { // 传递true,表示:返回键需要返回指定页面 (需要双方提供商量好) controlBackButton("true"); window.toUrl = `${baseUrl.developmentUrl.host2}/healthh5/`; },在页面初始化调用
// 第一步: if (window.history && window.history.pushState) { history.pushState(null, null, document.URL); window.addEventListener("popstate", this.goBack, false); }页面销毁事件,调用
destroyed() { // 第二步: window.removeEventListener("popstate", this.goBack, false); },方法定义:里面方法的内容,根据项目情况而定 (这里:根据手机操作系统执行不同的内容)
goBack(){ var u = navigator.userAgent; var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //g var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端 if (isAndroid) { healthJSSDK.webviewClose( function(e) { console.log("webviewClose", e) }); } if (isIOS) { window.webkit.messageHandlers.guidance.postMessage("{支付结果}"); } },