Created
October 22, 2014 19:02
-
-
Save Morasta/658af9b558a508feee7b to your computer and use it in GitHub Desktop.
jquery getUrlVars extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//adapted from http://stackoverflow.com/questions/6001839/check-whether-a-url-variable-is-set-using-jquery | |
//modified to return empty array when no ? params are set | |
$.extend({ | |
getUrlVars: function(){ //return all vars set in $_GET | |
var vars = [], hash; | |
if (window.location.href.indexOf('?') != -1) { | |
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); | |
for(var i = 0; i < hashes.length; i++) | |
{ | |
hash = hashes[i].split('='); | |
vars.push(hash[0]); | |
vars[hash[0]] = hash[1]; | |
} | |
} | |
return vars; | |
}, | |
getUrlVar: function(name){ //return single var value by name | |
return $.getUrlVars()[name]; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment