使用javascript删除查询字符串

使用javascript删除查询字符串,javascript,Javascript,我的url包含一些查询字符串“?v=1” 我使用以下方法清理我的url <script type="text/javascript"> var uri = window.location.toString(); if (uri.indexOf("?") > 0) { var clean_uri = uri.substring(0, uri.indexOf("?")); window.history.replaceState({}, document.title,

我的url包含一些查询字符串“?v=1” 我使用以下方法清理我的url

<script type="text/javascript">
var uri = window.location.toString();
if (uri.indexOf("?") > 0) {
    var clean_uri = uri.substring(0, uri.indexOf("?"));
    window.history.replaceState({}, document.title, clean_uri);
}
</script>

var uri=window.location.toString();
如果(uri.indexOf(“?”)大于0){
var clean_uri=uri.substring(0,uri.indexOf(“?”);
window.history.replaceState({},document.title,clean_uri);
}

无论如何,我想处理查询,即使我刷新页面。如何实现此目的?

您只能尝试此代码一次:-

<script type="text/javascript">

if(window.location.href.indexOf("?") > -1) 
{
   var uri         = window.location.toString();
   var newURL      = uri.split("?");
   window.location = newURL[0];
}
</script>

if(window.location.href.indexOf(“?”>-1)
{
var uri=window.location.toString();
var newURL=uri.split(“?”);
window.location=newURL[0];
}

使用
window.location.hostname+window.location.pathname
它会不断重新加载页面