Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to change the query parameter of the url in javascript

// Construct URLSearchParams object instance from current URL querystring.
var queryParams = new URLSearchParams(window.location.search);
 
// Set new or modify existing parameter value. 
queryParams.set("myParam", "myValue");
 
// Replace current querystring with the new one.
history.replaceState(null, null, "?"+queryParams.toString());

// OR do a push to history
tory.pushState(null, null, "?"+queryParams.toString());
Comment

create url with query parameters javascript

var query = new URLSearchParams();
query.append("KEY", "VALUE");
var url = "http://site.com/page?" + query.toString();
Comment

javascript set query parameters in url

function updateURLParameter(url, param, paramVal)
{
    var TheAnchor = null;
    var newAdditionalURL = "";
    var tempArray = url.split("?");
    var baseURL = tempArray[0];
    var additionalURL = tempArray[1];
    var temp = "";

    if (additionalURL) 
    {
        var tmpAnchor = additionalURL.split("#");
        var TheParams = tmpAnchor[0];
            TheAnchor = tmpAnchor[1];
        if(TheAnchor)
            additionalURL = TheParams;

        tempArray = additionalURL.split("&");

        for (var i=0; i<tempArray.length; i++)
        {
            if(tempArray[i].split('=')[0] != param)
            {
                newAdditionalURL += temp + tempArray[i];
                temp = "&";
            }
        }        
    }
    else
    {
        var tmpAnchor = baseURL.split("#");
        var TheParams = tmpAnchor[0];
            TheAnchor  = tmpAnchor[1];

        if(TheParams)
            baseURL = TheParams;
    }

    if(TheAnchor)
        paramVal += "#" + TheAnchor;

    var rows_txt = temp + "" + param + "=" + paramVal;
    return baseURL + "?" + newAdditionalURL + rows_txt;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: modules.exports javascript 
Javascript :: javascript Insert Item to Map 
Javascript :: how to pass props in react 
Javascript :: js chrome extension get current url 
Javascript :: create text node in javascript 
Javascript :: react routes not found on refresh 
Javascript :: Angular passing function as component input 
Javascript :: nodejs grpc 
Javascript :: jquery callback function example 
Javascript :: react native splash screen 
Javascript :: es6 class example 
Javascript :: array unshift 
Javascript :: javasript object 
Javascript :: http_proxy 
Javascript :: samoglasnici-vowels 
Javascript :: vue on page link or anchor 
Javascript :: how to use axios filter 
Javascript :: jquery plugins 
Javascript :: remix js 
Javascript :: get last item in array js 
Javascript :: rest parameter 
Javascript :: javascript debugging 
Javascript :: date time react component 
Javascript :: react native update helper 
Javascript :: vuetify select array 
Javascript :: what is a blob in javascript 
Javascript :: javascript 00:00:00 / 00:00:00 clock 
Javascript :: react and node js sample project github 
Javascript :: play mp4 vue js 
Javascript :: _onResize vue leaflet 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =