Is there a way to easily handle manipulating URLs in JavaScript?
A bit of context:
I want to use ThickBox, the popular jQuery modal popup box, but unobtrusively. According to the ThickBox documentation I have to give all links that I want to be made modal a CSS class of "thickbox" and change the URL from...
...to:
http://www.mysite.com/mypopup?height=200&width=300
I want to make this happen only if JavaScript is enabled.
So I get all links using jQuery and "hack" a detect for the '?' character in the URL, appending "&height..." or "?height..." accordingly.
In the grander scheme of things, this might muddle stuff up if the URL already has a "height" parameter, in which case I might just want to update the existing one as opposed to give it two.
It all smells a little.
I feel like I'm hacking code that can/must have been done properly once already!
So my question is:
Is there something in the JavaScript world (plugin or not) that would enable me to something like this:
var url = Url(elm.attr("href"));
url.parameter("width", "300");
url.parameter("height", "200");
elm.attr("href", url.toString())
Or:
var height = Url(elm.attr("href")).parameter("height");