Remove URL parameters without refreshing page

前端 未结 13 995
执念已碎
执念已碎 2020-12-07 08:00

I am trying to remove everything after the \"?\" in the browser url on document ready.

Here is what I am trying:

jQuery(document).ready(function($)          


        
13条回答
  •  一个人的身影
    2020-12-07 08:21

    //Joraid code is working but i altered as below. it will work if your URL contain "?" mark or not
    //replace URL in browser
    if(window.location.href.indexOf("?") > -1) {
        var newUrl = refineUrl();
        window.history.pushState("object or string", "Title", "/"+newUrl );
    }
    
    function refineUrl()
    {
        //get full url
        var url = window.location.href;
        //get url after/  
        var value = url = url.slice( 0, url.indexOf('?') );
        //get the part after before ?
        value  = value.replace('@System.Web.Configuration.WebConfigurationManager.AppSettings["BaseURL"]','');  
        return value;     
    }
    

提交回复
热议问题