Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JQuery - GET URL Parameter value
// Given a query string "?to=email&why=because&first=John&Last=smith"
// getUrlVar("to") will return "email"
// getUrlVar("last") will return "smith"
// Slightly more concise and improved version based on http://www.jquery4u.com/snippets/url-parameters-jquery/
function getUrlVar(key){
var result = new RegExp(key + "=([^&]*)", "i").exec(window.location.search);
return result && unescape(result[1]) || "";
}
// To convert it to a jQuery plug-in, you could try something like this:
(function($){
$.getUrlVar = function(key){
var result = new RegExp(key + "=([^&]*)", "i").exec(window.location.search);
return result && unescape(result[1]) || "";
};
})(jQuery);
@cansadadeserfeliz
Copy link

cansadadeserfeliz commented Apr 3, 2014

thank you for sharing this!

@eleanorz
Copy link

eleanorz commented Sep 12, 2014

thankyou also, very helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment