Created
June 12, 2013 22:55
-
-
Save shakesoda/5769846 to your computer and use it in GitHub Desktop.
snippet for parsing a get variable out of a url
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 findVar(attr) { | |
| var url = location.href.split("#")[0]; | |
| var search = new RegExp(attr + "=.*?(?=[#&]|$)"); | |
| var result = search.exec(url); | |
| if (result !== null) { | |
| result = result[0].split("=")[1]; | |
| if (/^-?\d+(\.\d+)?$/.test(result)) | |
| return Number(result); | |
| else | |
| return result; | |
| } else return null; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment