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

javascript add update query parameter to url

function update_query_parameters(key, val) {
   uri = window.location.href
      .replace(RegExp("([?&]"+key+"(?=[=&#]|$)[^#&]*|(?=#|$))"), "&"+key+"="+encodeURIComponent(val))
      .replace(/^([^?&]+)&/, "$1?");
   return uri;
}
// examples: the following may update ?page=4 in url and redirects to 
window.location.href = update_query_parameters('page', '4);
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 :: reactjs absolute import 
Javascript :: disable back button in react native 
Javascript :: js copy a div 
Javascript :: socket io leave all rooms 
Javascript :: how to disable mouse right click in html page 
Javascript :: bootstrap dropdown not working in angular 8 
Javascript :: parentelement javascript 
Javascript :: Error: Error: Could not resolve [object Object] / undefined at Scope.resolve 
Javascript :: javascript scroll down 
Javascript :: close bootstrap modal with javascript 
Javascript :: firebase get current user javascript 
Javascript :: javascript copy an object without reference 
Javascript :: vedere se radio button è cliccato js 
Javascript :: regex para telefone celular 
Javascript :: electron communicate between main and renderer 
Javascript :: convert the following 2 d array into 1 d array in javascript 
Javascript :: js make element invisible 
Javascript :: javascript clear all intervals 
Javascript :: reactjs firebase where map value 
Javascript :: capitalize in javascript 
Javascript :: jquery on load button click 
Javascript :: find an object in an array of objects javascript 
Javascript :: javascript replace string 
Javascript :: how to print two arrays side by side in javascript 
Javascript :: jquery test div exists 
Javascript :: angular lifecycle hooks 
Javascript :: npm 
Javascript :: jquery data-toggle modal and tooltip 
Javascript :: how to reset auto numeric js for input 
Javascript :: javascript excel column letter to number 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =