Chris W. Parker wrote: > On Tuesday, October 31, 2006 10:46 AM Luke Lutman <> said: > >> Have a look at this recent thread :-) >> > http://www.nabble.com/method-plugin-for-getting-query-string-vars--tf248 > 1232.html#a6919130 > > I read through this and tried to implement your first suggestion but I > notice that everything takes location.search and parses that. I want to > use it in the following way: > > theHref = $(this).attr("href").query(); > > Your function is: > > jQuery.query = function() { > var r = {}; > var q = location.search; > q = q.replace(/^\?/,''); // remove the leading ? > q = q.replace(/\&$/,''); // remove the trailing & > jQuery.each(q.split('&'), function(){ > var key = this.split('=')[0]; > var val = this.split('=')[1]; > // convert floats > if(/^[0-9.]+$/.test(val)) > val = parseFloat(val); > // ingnore empty values > if(val) > r[key] = val; > }); > return r; > }; > > I'm not sure how to modify that function to do what I want (considering > my current lack of JS/jQuery syntax). Would you mind showing me what to > do? > > > Thank you, > Chris. > > _______________________________________________ > jQuery mailing list > discuss@jquery.com > http://jquery.com/discuss/ >
RFC3986 (URI Generic Syntax) presents a regular expression for parsing generic URI's: http://tools.ietf.org/html/rfc3986#page-50 Something like this (not tested): jQuery.parseURI = function(uri) { var m = /^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/.exec(uri); return { scheme: m[2], authority: m[4], path: m[5], query: m[7], fragment: m[9] }; } So: $.parseURI($(this).attr("href")).query would return the query string, which can then be parsed by the function above, or combine the two functions. - Mark Gibson _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/