Created
March 9, 2015 14:17
-
-
Save justinobney/3a4b9032bee0938c4b3d to your computer and use it in GitHub Desktop.
get querystring params
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
function gup(name, url, defaultValue) { | |
if (!url) url = location.href; | |
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); | |
var regexS = "[\\?&]" + name + "=([^&#]*)"; | |
var regex = new RegExp(regexS); | |
var results = regex.exec(url); | |
return (results == null ? null : results[1]) || defaultValue; | |
} | |
var id = gup('id', document.location.toString(), '50'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment