Jquery 如何重新加载带有参数的页面?
我想用一些参数重新加载一个页面,我使用了下面的代码-Jquery 如何重新加载带有参数的页面?,jquery,Jquery,我想用一些参数重新加载一个页面,我使用了下面的代码- location.reload('https://makemyfoam.com/checkout#three'); 但它会在https://makemyfoam.com/checkout 我使用javascript代码- window.location.href = window.location.href + "#three"; 它只在URL中添加#三个,而不是加载页面 但是我想在https://makemyfoam.com/che
location.reload('https://makemyfoam.com/checkout#three');
但它会在https://makemyfoam.com/checkout
我使用javascript代码-
window.location.href = window.location.href + "#three";
它只在URL中添加#三个,而不是加载页面
但是我想在https://makemyfoam.com/checkout#three
您可以试试
const loc = window.location;
loc.href = loc.origin + loc.pathname + "#three";
loc.reload()
PS:请注意使用location.origin+location.pathname+'#anchor'
而不是location.href+'#anchor'
以避免出现类似情况:
https://www.example.com/page#anchor1#anchor2#anchor3