页面控制显示返回头部

    技术2022-07-10  137

    页面控制显示返回头部(大佬提供)

    调用原生方法 window.ele_med_insurance.controlBackButton(b); b = 'true' 页面控制返回跳转; b = 'false' 原生控制返回方法; 例 页面控制返回跳转; if(window.ele_med_insurance){ //controlBackButton true 页面控制返回跳转 window.controlBackButton window.ele_med_insurance.controlBackButton('true'); window.controlBackButton = function(){ if(window.ele_med_insurance){ if(fun){ fun(); } } }; }

    vue项目 情形一:返回方法需要其他人提供 controlBackButton

    在全局定义方法: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/`; },

    适用场景:H5 和 app

    在页面初始化调用

    // 第一步: 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("{支付结果}"); } },
    Processed: 0.012, SQL: 9