Skip to content

Instantly share code, notes, and snippets.

@can3p
Created May 19, 2011 08:10
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save can3p/980382 to your computer and use it in GitHub Desktop.
Save can3p/980382 to your computer and use it in GitHub Desktop.
url parsing on coffeescript
parseUrl = ( url = location.href ) ->
params = {}
( ( parts = part.split( "=" ) ) && params[ parts[0] ] = parts[1] for part in ( url.split "?" ).pop().split "&" if url.indexOf( "?" ) != -1 ) && params || {}
$ ->
console.log parseUrl( "http://test.com/?a=b" )
console.log parseUrl( "http://test.com" )
console.log parseUrl()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment