Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 此网页如何更改地址栏中的URL查询参数?_Javascript_Html_Url_Address Bar - Fatal编程技术网

Javascript 此网页如何更改地址栏中的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的

初始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);
    },