关于购物车下单-订单跳转及返回问题解决方案

通过商品或者购物车进入下单页面下单页面确认信息 提交订单进入订单页面在订单页面点击返回按钮

返回至下单页面

导致的问题:

在下单页面 如果是购物车中的商品 因为购物车中商品已经提交订单了,所以会提示购物车信息无效

解决方案:

第一种解决方案:

如果是通过下单页进入的订单详情 通过监听订单详情页面的返回事件 如果用户点击了返回 则返回两次主要代码如下

 (function(){
 window.onpopstate = function(event) {
 window.history.go(-2);
 };
 window.history.pushState(null, null, "#backIgnoreConfirm");
 })();
第二种解决方案:

在下单页 点击提交订单的时候 将当前页面的url替换为订单详情页 返回的时候就会忽略下单页location.replace(url);但是使用这种方案安卓会出现问题

原因:stackoverflow.com/questions/1…

解决方案:

//替换当前页面地址 兼容安卓的replace
function locationReplace(url){
 if(history.replaceState){
 history.replaceState(null, document.title, url);
 history.go(0);
 }else{
 location.replace(url);
 }
}

未经作者允许 请勿转载,谢谢 :)

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.154.0. UTC+08:00, 2026-02-26 07:12
浙ICP备14020137号-1 $访客地图$