Skip to content

Instantly share code, notes, and snippets.

@joshuafredrickson
Forked from alkos333/gist:1771618
Last active December 16, 2015 06:09
Show Gist options
  • Save joshuafredrickson/5389226 to your computer and use it in GitHub Desktop.
Save joshuafredrickson/5389226 to your computer and use it in GitHub Desktop.
jQuery: Get query string variable
// Given a query string "?to=email&why=because&first=John&Last=smith"
// $.getUrlVar("to") will return "email"
(function($){
$.getUrlVar = function(key){
var result = new RegExp(key + "=([^&]*)", "i").exec(window.location.search);
return result && unescape(result[1]) || "";
};
})(jQuery);
@LancePrice
Copy link

JavaScript
// Given a query string "?to=email&why=because&first=John&Last=smith"
// getUrlVar("to") will return "email"
// getUrlVar("last") will return "smith"

@LancePrice
Copy link

Awesome tanks

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