remove url parameters with javascript or jquery

前端 未结 10 2421
臣服心动
臣服心动 2020-12-25 10:15

I am trying to use the youtube data api to generate a video playlist.

However, the video urls require a format of:

youtube.com/watch?v=3sZOD3xKL0Y
<         


        
10条回答
  •  轮回少年
    2020-12-25 11:05

    //user113716 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;     
    }
    

提交回复
热议问题