监听手机返回事件

history.pushState(null, null, document.URL);
window.addEventListener('popstate', function() { // 监听回退按钮
//alert('我监听到了回退事件'); // 在回退时进行某种操作。

  //手动返回页面时重新加载该页面
  location.href="<%=request.getContextPath()%>/ActiveCtl/invitationCard?agentId="+agentId; 
},false);

以上代码均在实际项目中存在

上述代码可优化为:

$(document).ready(function(){
    history.pushState(null, null, document.URL);
    window.addEventListener('popstate', function() {        
        location.href = document.URL;
    },true);
});

猜你喜欢

转载自www.cnblogs.com/yinyl/p/9438219.html