简体   繁体   English

go 通过历史跳过同一页返回

[英]go back through history skipping the same page

So i am using this js code to go back to previous page所以我使用这个 js 代码来 go 返回上一页

 function goBack() {
  window.history.back();
}


<span onclick="goBack()">back</span>

example:例子:

home > product > product add to cart > click back return to home首页 > 产品 > 产品加入购物车 > 点击返回返回首页

now when i add product to cart the page reload and when i click back it return to same page现在,当我将产品添加到购物车时,页面重新加载,当我点击返回时,它返回到同一页面

is there any possible way to make the window.history.back ignore if it return to same page?如果 window.history.back 返回到同一页面,是否有任何可能的方法来忽略它?

You can create a flag in the case of adding a product to the cart and if the flag is true use:您可以在将产品添加到购物车的情况下创建一个标志,并且如果该标志是真实的,请使用:

window.history.go(-2);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM