Change URL parameters

前端 未结 26 2192
孤独总比滥情好
孤独总比滥情好 2020-11-22 08:40

I have this URL:

site.fwx?position=1&archiveid=5000&columns=5&rows=20&sorting=ModifiedTimeAsc

what I need is to be able to

26条回答
  •  礼貌的吻别
    2020-11-22 09:17

    my function support removing param

    function updateURLParameter(url, param, paramVal, remove = false) {
            var newAdditionalURL = '';
            var tempArray = url.split('?');
            var baseURL = tempArray[0];
            var additionalURL = tempArray[1];
            var rows_txt = '';
    
            if (additionalURL)
                newAdditionalURL = decodeURI(additionalURL) + '&';
    
            if (remove)
                newAdditionalURL = newAdditionalURL.replace(param + '=' + paramVal, '');
            else
                rows_txt = param + '=' + paramVal;
    
            window.history.replaceState('', '', (baseURL + "?" + newAdditionalURL + rows_txt).replace('?&', '?').replace('&&', '&').replace(/\&$/, ''));
        }
    

提交回复
热议问题