javascript add query string to url

function updateQueryStringParameter(uri, key, value) {
  var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
  var separator = uri.indexOf('?') !== -1 ? "&" : "?";
  if (uri.match(re)) {
    return uri.replace(re, '$1' + key + "=" + value + '$2');
  }
  else {
    return uri + separator + key + "=" + value;
  }
}

3.7
10
Awgiedawgie 440220 points

                                    function setParam(uri, key, val) {
    return uri
        .replace(RegExp("([?&]"+key+"(?=[=&#]|$)[^#&]*|(?=#|$))"), "&"+key+"="+encodeURIComponent(val))
        .replace(/^([^?&]+)&/, "$1?");
}

3.7 (10 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
add to query string js how to properly append query string in url using javascript how to add a query string to a url in js Apply query string to URL javascript Javascript add query parameter to URL var javascript get url parameters and add query add query string into current URL javascript set url query string javascript javascript add query to url js append querystring to url js add query param to current url add query parameter to url string in javascript url add query parameter javascript add query string on url add query params to url javascript html how to add query string in url how to add query parameters to url javascript how to add query string in js by location how to add query string in js add query param to strong js javascript append query string to current url how to add query string to url using javasript add a query string to url add query string in url javascript how to add query parameter in url in javascript add query string to url js how to set query string in url using javascript add query parameters javascript add url query string javascript javascript add query param js pass url as query string add query string to javascript add query to url cuejs how to pass url in query string javascript how to add query parameter to url in js javascript create url with query string add query param to existing js adding query string to url js add querystring to current url javascript set url query string add query string to url html add query string to url add query string parameters to url javascript javascript add query parameter to current url how to add query parameter to url javascript javascript url add query parameter javascript add query string parameter to url how to add query parameter to url in javascript setting query param js set query string javascript url add query param javascript function to add query params add value to query param javascriipt js add params query javascript add to query string how to add query parameter to url js add query string params to url javascript add query string params to url add query string params js add query to url Javascript add query param to current url javascript add query parameter to url how to add query params in node js js add querys string to ahref how to append query string in url using javascript js add query param to url js location add query string append query parameter to url javascript js add query string to url js append a query params to url js add query params to url js put query params to url javascript function add query params to url add query string url in js how to append a query string to a url in javascript js append query param to url add query parameter to url javascript add query to url js how to add query string in url add query param to url js js add query param to currenr url how to add query string to url javascript adding paran to location url how to change querystring to url add query string to url javascript javascript add query string to url append to the query sstring ks how to append query string to url javascript js append get parameter js add query parameters add query parameters to url javascript add value to url js add param to query param list js add param inside query object of URL params to append to URL javscript array of params and then append to url add parameter to url js add url parameter in typescript javascript url append parameter javascript how to get current url parameters jquery and replace them add url parameters javascript javascript add query params javascript append new quaery param to URL js add query param
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source