场景:从Controller方法跳转至 跳转页面,在跳转页面获取临时免登授权码,再跳入主页,从主页点击返回直接退出当前页。
跳转页面代码:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> </head> <script src="../js/jquery.js"></script> <script src="https://g.alicdn.com/dingding/dingtalk-jsapi/2.10.3/dingtalk.open.js"></script> <script> dd.ready(function () { dd.runtime.permission.requestAuthCode({ corpId: "企业的corpId", onSuccess: function (result) { var code = result.code; //获取的免登授权码,用于获取用户id if (code != null){ window.location.href='需要跳转的地址?code='+code; }else{ alert("请求失败请重试或联系管理人员") } } }); }); dd.ready(function() { document.addEventListener('backbutton', function(e) { // 在这里处理你的业务逻辑 e.preventDefault(); //backbutton事件的默认行为是回退历史记录,如果你想阻止默认的回退行为,那么可以通过preventDefault()实现 }); }); </script> <body> <h1 style="text-align: center">正在加载,请稍等...</h1> </body> </html>
主页面代码:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <script src="https://g.alicdn.com/dingding/dingtalk-jsapi/2.10.3/dingtalk.open.js"></script> </head> <script type="text/javascript"> /** 回退事件 **/ dd.ready(function() { document.addEventListener('backbutton', function(e) { // 在这里处理你的业务逻辑 e.preventDefault(); dd.biz.navigation.close({ onSuccess : function(result) { alert(JSON.stringify(result)); }, onFail : function(err) {} }) }); }); /** 回退事件 **/ </script> <body> 欢迎... </body> </html>