Created
January 19, 2010 16:16
-
-
Save bcalloway/281046 to your computer and use it in GitHub Desktop.
jQuery script to grab params from URL
This file contains 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
$.extend({ | |
getUrlVars: function(){ | |
var vars = [], hash; | |
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 $.getUrlVars()[name]; | |
} | |
}); | |
// Get object of URL params | |
var allVars = $.getUrlVars(); | |
// This will grab all keyword params (e.g. http://mydomain.com?keywords=foo) | |
var keywords = $.getUrlVar('keywords'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment