[thelist] JS: Token replacement

Joshua Olson joshua at waetech.com
Wed Jan 22 09:00:01 CST 2003


Hi everybody,

I am looking for the most foolproof JavaScript code that allows me to
replace tokens within a query string.  It needs to work something like this:

qs_replace('http://www.domain.com?foo=bar', 'foo', 'bar2');

That would return:

http://www.domain.com?foo=bar2

Other cases it would need to handle:

1.  Passing the third parameter as the blank string should remove the token.
2.  If the token specified by parameter 2 is not already in the url, it
should be added.
3.  It should be able to handle cases when the ? is not already appended to
the string.

Anybody seen a really good implementation of this type of function?

TIA,
-joshua




More information about the thelist mailing list