replaceState 实现返回从新定位

在web 开发中,选择列表分类,在中商品, 详情页面后,返回的时候我们想定位到原来选择的分类 就需要借助window.history.replaceState来实现

   function getProductUrl(cid, number) {
            if (history && history.pushState) {
                // 替换当前url,便于返回的时候定位
                window.history.replaceState(null, "", "/xxxx/Index/" + cid);
            }
            window.location.href = '/product/' + number;
        }

 

posted @ 2017-02-23 18:23  dragon.net  阅读(684)  评论(0编辑  收藏  举报