Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. EricYue2012 renamed this gist Nov 18, 2013. 1 changed file with 0 additions and 0 deletions.
  2. EricYue2012 renamed this gist Nov 14, 2013. 1 changed file with 0 additions and 0 deletions.
  3. EricYue2012 created this gist Nov 14, 2013.
    10 changes: 10 additions & 0 deletions javascript_update_url_query_parameter_value
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    function updateQueryStringParameter(uri, key, value) {
    var re = new RegExp("([?|&])" + key + "=.*?(&|$)", "i");
    separator = uri.indexOf('?') !== -1 ? "&" : "?";
    if (uri.match(re)) {
    return uri.replace(re, '$1' + key + "=" + value + '$2');
    }
    else {
    return uri + separator + key + "=" + value;
    }
    }