Created
March 12, 2014 00:21
-
-
Save pntrivedy/9498010 to your computer and use it in GitHub Desktop.
I was searching for a way in javascript by which I can get url query parameters and found this here : http://jsperf.com/querystring-with-javascript probably the best solution.
This file contains 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
<script> | |
window.getParameterByName = function(name) { | |
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); | |
var regexS = "[\\?&]" + name + "=([^&#]*)"; | |
var regex = new RegExp(regexS); | |
var results = regex.exec(window.location.href); | |
if (results == null) return ""; | |
else return decodeURIComponent(results[1].replace(/\+/g, " ")); | |
} | |
</script> | |
usage: | |
<script> | |
var search = window.getParameterByName("q"); | |
var value = window.getParameterByName("value"); | |
var undef = window.getParameterByName("undefinedstring"); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment