4

I was looking over this question and searching google but I didn't find any update, so I am wondering if any of you know anything more recent because the last update on

https://github.com/blairmitchelmore/jquery.plugins was in 2009 and 2010 on https://github.com/cowboy/jquery-bbq

Or any other ideas? I need to add/change/remove parameters to my url

Community
  • 1
  • 1
Alex
  • 7,538
  • 23
  • 84
  • 152
  • You'd like to alter the URL after having a loaded page? – Hacknightly Jan 25 '12 at 20:01
  • yes... exactly, after the page has been loaded – Alex Jan 25 '12 at 20:02
  • This is tough to do, mainly because of the security issues involved. Are you unable to use either of the plugins you linked to? I'd imagine these would only manipulate the hash value. – Hacknightly Jan 25 '12 at 20:07
  • i didn't tried them out because I am looking first for a more recent version to see if something... if not than I will see if they work. From 2009 to 2012 something better could've appeared – Alex Jan 25 '12 at 20:12
  • Manipulating query parameters is such a basic thing that it doesn't hardly matter whether the code is brand new or several years old. – simon Jan 25 '12 at 20:15

1 Answers1

10

Its easy to do by pure JS.

See this code from www.samaxes.com

var queryParameters = {}, queryString = location.search.substring(1),
    re = /([^&=]+)=([^&]*)/g, m;

while (m = re.exec(queryString)) {
    queryParameters[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
}

// Add new parameters or update existing ones
queryParameters['newParameter'] = 'new parameter';
queryParameters['existingParameter'] = 'new value';
location.search = $.param(queryParameters);

Its not flawless. But at least it can give you some idea.

Update 1:
Here is a function I wrote for another answer (cant remember). It works perfect.

Shiplu Mokaddim
  • 56,364
  • 17
  • 141
  • 187