Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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 :: leaflet circle get bounds 
Javascript :: how to get a user input in js 
Javascript :: node js event emitter 
Javascript :: how to unselect input javascript 
Javascript :: react native red triangle up 
Javascript :: node path relative 
Javascript :: cart page url in shopify 
Javascript :: javascript regex Zero or one occurrence 
Javascript :: use setstate in function component 
Javascript :: how to display array values in javascript 
Javascript :: puppeteer headless 
Javascript :: javascript regex single line 
Javascript :: axios delete with data 
Javascript :: http request javascript 
Javascript :: react navigation history clear 
Javascript :: js fetch api 
Javascript :: hide div after 5 seconds vue js 
Javascript :: javascript 2 return values 
Javascript :: json stringify 
Javascript :: js check if array is empty 
Javascript :: jquery copy table to clipboard 
Javascript :: redux dispatch no connect 
Javascript :: generate random color array javascript 
Javascript :: react testing library for hooks 
Javascript :: cookie options 
Javascript :: date difference moment js 
Javascript :: infinite scroll jquery 
Javascript :: hide_node example jstree 
Javascript :: github actions ssh 
Javascript :: python parse single quote json 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =