Javascript 此网页如何更改地址栏中的URL查询参数?
初始URL为Javascript 此网页如何更改地址栏中的URL查询参数?,javascript,html,url,address-bar,Javascript,Html,Url,Address Bar,初始URL为 https://robertbarakett.com/products/the-barakett-t-hoodie?option1=Blue+night&option2=S 我跟踪了HTTP请求。它只执行1个重定向: 从 到 但是,地址栏中的最终URL是 https://robertbarakett.com/products/the-barakett-hoodie-black?variant=31966791729263. 我读到关于在不重新加载页面的情况下更改URL的
https://robertbarakett.com/products/the-barakett-t-hoodie?option1=Blue+night&option2=S
我跟踪了HTTP请求。它只执行1个重定向:
从
到
但是,地址栏中的最终URL是
https://robertbarakett.com/products/the-barakett-hoodie-black?variant=31966791729263.
我读到关于在不重新加载页面的情况下更改URL的内容:
由于加载网页后没有导航历史记录,因此它将排除
window.history.pushState
。可能它使用了窗口.history.replaceState
?我在页面的源代码中进行了搜索,没有找到replaceState
的任何用法。那么如何验证它是否使用了replaceState
或其他技术呢?正在使用window.history.replaceState
在:
它有:
_updateHistoryState: function(variant) {
if (!history.replaceState || !variant) {
return;
}
var newurl = window.location.protocol + '//' + window.location.host + window.location.pathname + '?variant=' + variant.id;
window.history.replaceState({path: newurl}, '', newurl);
},
是源中唯一分配变量的位置
通过下载站点(右键单击另存为),然后搜索
?variant
,可以找到该站点!我自己搜索了variant
,找到了几个参考资料。但是你怎么能追踪到那个特定的JS文件呢?有相当多的JS files.np,有很多变量
,但只有一个?变量
。我保存了页面,在vs代码中打开,然后搜索Ctrl-Shift-F,这是唯一显示的文件。。手动查看每个文件或请求响应可能需要很长时间。我们已经意识到“右键单击另存为”的含义,这就成功了!
https://robertbarakett.com/products/the-barakett-hoodie-black?variant=31966791729263.
_updateHistoryState: function(variant) {
if (!history.replaceState || !variant) {
return;
}
var newurl = window.location.protocol + '//' + window.location.host + window.location.pathname + '?variant=' + variant.id;
window.history.replaceState({path: newurl}, '', newurl);
},