[英]How to go back to the previous page, but not counting the url variables in the js
I want to go back using something like window.history.back()
, but I'm generating urls with variables in php, like: 我想返回使用诸如
window.history.back()
类的东西,但是我正在用 php中的变量生成URL,例如:
https://www.amazon.com/Legend-Zelda-Breath-Wild-Nintendo-Switch/dp/B01MS6MO77/ref=br_asw_pdt-4?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=&pf_rd_r=M6RDNMRTP3QXJFK6JR12&pf_rd_t=36701&pf_rd_p=f8585743-c043-4665-80a7-0cc5fe97d596&pf_rd_i=desktop https://www.amazon.com/Legend-Zelda-Breath-Wild-Nintendo-Switch/dp/B01MS6MO77/ref=br_asw_pdt-4?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=&pf_rd_r=M6RDNMRTP3QXJFK6JR12&pf_rd_t=36701&pf_rd_p=f8585743-c043-4665-80a7- 0cc5fe97d596&pf_rd_i =桌面
You can see the variables after the ?, which itself is after the 4. 您可以在?之后看到变量,后者本身在4之后。
If I went to that page without the variables, it would look like: 如果我在没有变量的情况下转到该页面,则它看起来像:
https://www.amazon.com/Legend-Zelda-Breath-Wild-Nintendo-Switch/dp/B01MS6MO77/ref=br_asw_pdt-4 https://www.amazon.com/Legend-Zelda-Breath-Wild-Nintendo-Switch/dp/B01MS6MO77/ref=br_asw_pdt-4
So after going to the page with url variables from the ulr without variables, if I click in the button with window.history.back()
, It will take me back to the same page with the same url but without the variables. 因此,从 ULR要去页面 URL变量不变量,如果我在点击该按钮后
window.history.back()
它会带我回到同一页面相同的URL,但没有变数。
How can I prevent this? 我该如何预防? I want to go back but ignore similar urls (even if they're different just because of the variables).
我想返回,但是忽略相似的url(即使只是因为变量而不同)。
Is there any function like: window.history.ignoreUrlVariables()
? 有没有像
window.history.ignoreUrlVariables()
这样的函数?
There is no such function built into the history API but you can implement one yourself. 历史API中没有内置此类功能,但您可以自己实现。
You can go back multiple pages with window.history.go(-10)
(back 10 pages). 您可以使用
window.history.go(-10)
返回多页(返回10页)。
With this in mind if you add to a counter every time that you alter the URL variables then when you finally want to go back simply call window.history.go(-counter)
which will take you back to the page before you started editing the URL. 考虑到这一点,如果您每次更改URL变量时都添加一个计数器,那么当您最终要返回时,只需调用
window.history.go(-counter)
,它将带您返回页面,然后开始编辑URL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.