Skip to content

Instantly share code, notes, and snippets.

@mrchess
Created February 25, 2013 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrchess/5032262 to your computer and use it in GitHub Desktop.
Save mrchess/5032262 to your computer and use it in GitHub Desktop.
URL parameter reader
###
A simple global function to help read URL parameters.
ex. www.google.com?value=1 -- URLY.get('value')
###
window.URLY =
get : (key) ->
key = key.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]")
regexS = "[\\?&]" + key + "=([^&#]*)"
regex = new RegExp(regexS)
results = regex.exec(window.location.href)
unless results?
""
else
decodeURIComponent results[1].replace(/\+/g, " ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment