Answers for "jquery change get parameter in url"

8

jquery get parameter from url

function GetUrlParameter(sParam)

{
    var sPageURL = window.location.search.substring(1);

    var sURLVariables = sPageURL.split('&');

    for (var i = 0; i < sURLVariables.length; i++)
    {
        var sParameterName = sURLVariables[i].split('=');

        if (sParameterName[0] == sParam)

        {
            return sParameterName[1];
        }
    }
}

And this is how you can use this function assuming the URL is,
http://dummy.com/?technology=jquery&blog=jquerybyexample.

var tech = GetUrlParameter('technology');
var blog = GetUrlParameter('blog');
Posted by: Guest on June-30-2020
0

update param in url jquery

var url = new URL('http://demourl.com/path?id=100');
var search_params = url.searchParams;

// add "topic" parameter
search_params.set('topic', 'main');

url.search = search_params.toString();

var new_url = url.toString();

// output : http://demourl.com/path?id=100&topic=main
console.log(new_url);
Posted by: Guest on February-09-2021

Code answers related to "jquery change get parameter in url"

Code answers related to "Javascript"

Browse Popular Code Answers by Language