Created
July 16, 2015 11:57
-
-
Save sohelamin/9cc56ffbdcb9bf5c708c to your computer and use it in GitHub Desktop.
Query String Get in JavaScript
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
function getQueryStringValue (key) { | |
return unescape(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + escape(key).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1")); | |
} | |
var utm_source = getQueryStringValue("utm_source"); |
Thanks, it helped me. Consider replacing unescape
with decodeURI
as that seems to be deprecated.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
example.com?utm_source=google
var utm_source = getQueryStringValue("utm_source");