<script>
$(document).ready(() => {
var isback =false;
if (window.performance.navigation.type == 0) {
console.log("表示当前页面是通过点击别的链接进入的");
}
if (window.performance.navigation.type == 1) {
console.log("表示当前页面是通过刷新加载的");
}
if (window.performance.navigation.type == 2) {
console.log("表示当前页面是通过点击后退按钮或者是通过history.go(-1)加载的");
//安卓端检测到从其他页面返回
isback =true;
//微信浏览器关闭当前窗口
document.addEventListener('WeixinJSBridgeReady', function() {
WeixinJSBridge.call('closeWindow');
}, false);
WeixinJSBridge.call('closeWindow');
}
//ios端检测从其他页面返回方法
pushHistory();
window.addEventListener("popstate", function(e) {
isback =true;
//微信浏览器关闭当前窗口
document.addEventListener('WeixinJSBridgeReady', function() {
WeixinJSBridge.call('closeWindow');
}, false);
WeixinJSBridge.call('closeWindow');
}, false);
function pushHistory() {
var state = {
title: "title",
url: "#"
};
window.history.pushState(state, "title", "#");
}
});
</script>