Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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 :: i18n react get current language 
Javascript :: count number of each element in array javascript 
Javascript :: how to change the text using jquery on click 
Javascript :: return empty new promise 
Javascript :: extract value from array of objects javascript 
Javascript :: select element as role in jquery 
Javascript :: conditionally changing styled components based on props 
Javascript :: js events 
Javascript :: iso to date javascript 
Javascript :: jquery make new variable with dynamic name 
Javascript :: miles to metres js 
Javascript :: how to remove comma from array in javascript 
Javascript :: javascript reset form 
Javascript :: electron disable menu 
Javascript :: jquery find div with data attribute value 
Javascript :: get hash js 
Javascript :: convert string number with commas decimal to number javascript 
Javascript :: What is the Difference between Undefined, undeclared, Null 
Javascript :: js Date(date).toLocaleString() MINUUTES 
Javascript :: javascript setattribute onclick function with parameters 
Javascript :: JSON.parse() error handling 
Javascript :: nodejs request 
Javascript :: js check if string includes from array 
Javascript :: create function replace all n javescript 
Javascript :: find and replace value in array of objects javascript 
Javascript :: javascript cors error 
Javascript :: js tab character 
Javascript :: jquery wait for all ajax requests to complete 
Javascript :: angular findindex object based array 
Javascript :: loop an object in javascript 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =