Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Mamdouh-Freelancer/1d44bca7b2fb24a8c45cfa9b185520a1 to your computer and use it in GitHub Desktop.
Save Mamdouh-Freelancer/1d44bca7b2fb24a8c45cfa9b185520a1 to your computer and use it in GitHub Desktop.
/*
@Mamdouh Freelancer
SO account: http://stackoverflow.com/users/7040620/
Github: https://github.com/Mamdouh-Freelancer
*/
//usage: location.href.param("key");
String.prototype.param = function(str) {
e = this.indexOf("?" + str + "=") > -1 ? "?" + str + "=" : "&" + str + "=";
return this.indexOf(e) == -1 ? undefined : this.split(e)[1].split("&")[0];
}
var url = "http://sub.domain.com/?key=value&option=value";
var k = url.param("key");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment