Forked from cgilchrist/replace_text_with_url_param.js
Created
April 11, 2022 14:22
-
-
Save nomad411/5c388afc9faa731f1367f2e67e625e6f to your computer and use it in GitHub Desktop.
Replace some text on your page with the value of a URL parameter
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 type="text/javascript"> | |
var getUrlParams = function() { | |
var params = {}, hash; | |
var hashes = decodeURI(window.location.href).replace(/\+/g," ").slice(window.location.href.indexOf('?') + 1).split('&'); | |
for (var i=0; i<hashes.length; i++) { | |
hash = hashes[i].split('='); | |
params[hash[0]] = hash[1]; | |
} | |
return params; | |
}; | |
jQuery(function() { | |
// This assumes you have a parameter in your URL called "utm_keyword" | |
var utm_keyword = getUrlParams()['utm_keyword']; | |
if (utm_keyword != undefined) { | |
// This assumes you've given an element on the page and ID of "keyword" | |
jQuery('#keyword').html(utm_keyword); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment