Skip to content

Instantly share code, notes, and snippets.

@BartlomiejSkwira
Created April 26, 2013 14:11
Show Gist options
  • Select an option

  • Save BartlomiejSkwira/5467644 to your computer and use it in GitHub Desktop.

Select an option

Save BartlomiejSkwira/5467644 to your computer and use it in GitHub Desktop.
Get query string param in CoffeScript
getParameterByName(name) ->
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]")
regexS = "[\\?&]" + name + "=([^&#]*)"
regex = new RegExp(regexS);
results = regex.exec(window.location.search)
if(results == null)
""
else
decodeURIComponent(results[1].replace(/\+/g, " "))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment