Suppose you have a URL:
http://www.example.com/whatever?this=that&where=when
How would you extract the value of the where
parameter (in this case when
)?
This is what I came up with -- I'm wondering if there's a better solution:
$.fn.url_param_value = function(param) {
var url = $(this).attr('href');
var regex = new RegExp(param + "=");
return $.grep(url.split("?")[1].split("&"), function(a) {
return a.match(regex);
})[0].split("=")[1];
}