Javascript 替换URL而不重定向

Javascript 替换URL而不重定向,javascript,html,Javascript,Html,从url中删除散列(无重定向) 编辑:Answer=window.history.pushState(“,”,window.location.href+”?userid=“+document.getElementById(“userid”).innerHTML) .replace()返回调整后的字符串。因此,至少,您需要执行类似于location.href=location.href.replace(“#”、“替换”)的操作我已经试过了,但它会在无限循环中发送什么??什么无限循环?只需if(lo

从url中删除散列(无重定向)


编辑:Answer=window.history.pushState(“,”,window.location.href+”?userid=“+document.getElementById(“userid”).innerHTML)

.replace()返回调整后的字符串。因此,至少,您需要执行类似于
location.href=location.href.replace(“#”、“替换”)的操作我已经试过了,但它会在无限循环中发送什么??什么无限循环?只需
if(location.href.indexOf('?userid='=-1)location.href+=“?userid=“+document.getElementById(“userid”).innerHTML
@PranavCBalan它们怎么会不重复?解释了为什么没有赋值的
replace
什么都不做。并解释了如何实现OP想要的。她的答案是上面答案的推论。谢谢dude:D我很感激
location.hash = "?userid=" + document.getElementById("userid").innerHTML;
location.href.replace('#', '');
window.history.pushState("", "", window.location.href +  "?userid=" + document.getElementById("userid").innerHTML);