1

I need help because I am trying to create a lib with javascript in order to create, modify, delete params in my url, I explain :

www.mydomain.com/thing/?id=1&et=67&type=chercher

How u can see, my params are random, it's dynamic, It's not every time the same url, I had this url, one time I can have ?id=1&et=67&type=chercher and other time I can have ?id=1&type=chercher or for example just ?id=1 or others params.

So it's not easy because of user action, the url with params will change, so is there an lib or an application written with javascript which can do this easily ?

Thx everyOne for your futures responses !!!!

11
  • And what are you trying to do with these parameters? And by the sounds of your question it seems you want a library to let you write the library you want to create..? Commented Jul 4, 2012 at 8:56
  • It's for a web application. Thoses params are filters in order to change a main div front of my web page Commented Jul 4, 2012 at 8:57
  • 1
    github.com/allmarkedup/jQuery-URL-Parser Commented Jul 4, 2012 at 8:57
  • 1
    Similar Question: stackoverflow.com/questions/2090551/… Commented Jul 4, 2012 at 9:00
  • 1
    try this medialize.github.com/URI.js Commented Jul 4, 2012 at 9:08

3 Answers 3

3

You are creating a library to manipulate URLs? Have you had a look at the existing solutions?

URI.js is something I can recommend. In its Readme URI.js links to a bunch of alternative solutions you could look into as well.

Sign up to request clarification or add additional context in comments.

Comments

1

Yes, absolutely. You can use the jQuery URL Parser plugin. Just make sure you include also jQuery in your page and not only the plugin.

2 Comments

jQuery is JavaScript... it's not only based on JavaScript, it's written in it. In fact, jQuery is nothing more than a huge JavaScript object, that is constructed in a self invoking function.
Oh, you think I didn't know it? Maybe I have a mistake with "Javascript only", that's true. But defenetly, I know that jQuery is a Javascript library
1

Do u need library which manipulate URL string? pass associative array(HASH) to function {a:2, b:3, c:4} and then go through this hash and form string.

Is this what u need?

To update - split string by & and downparse into HASH, and replace value by H['a'] = 4;

To delete - delete H["a"];

But better do not reinvent bicycle use tested solutions: http://code.google.com/p/jsuri/

7 Comments

for example, I need a function which can add params in my url, so for example we can have this prototype : function add_param_in_url(key, value); function remove_param_in_url(key); function get_value_by_key(key);
Hey, it's a cool lib but the function delete doesn't work it's very boring ! look at this example mydomain.com/expositions?q=books&domaine=1&domaine=2 when I call deleteQueryParam with the key 'domain' and the value '1' all the params domain are deleted .... I don't understand why that do that, an idea ?
An other question, how I can update the Url after having modify it ?
U write it does not work. Why do u need 2 parameters with same name anyway? one overwrite another when server side script will parse it.
U right about delete function. I already bug reported to authors of lib. Regarding update after modify - what do u mean? For me update and modify synonyms.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.