下面的javascript代码正在执行其预期的工作,即替换URL,但是页面不会停止重新加载/刷新。有办法阻止它吗?
原始页面是: www.xyz.com/used-vehicles
,但是我想自动使用该页面上的复选框过滤器选项,该选项将在二手车?search=certified%2Cpreowned
<script>
document.location.replace('/used-vehicles?search=certified%2Cpreowned');
答案 0 :(得分:0)
检查您的网址是否已经不包含search=certified%2Cpreowned
:
if(window.location.href.indexOf("search=certified%2Cpreowned") == -1){
window.location.replace('/used-vehicles?search=certified%2Cpreowned');
}