Skip to content

Instantly share code, notes, and snippets.

@danahmadi
Created April 4, 2018 20:05
Show Gist options
  • Save danahmadi/483cb8b4d24a2ea06acb73c68adeb145 to your computer and use it in GitHub Desktop.
Save danahmadi/483cb8b4d24a2ea06acb73c68adeb145 to your computer and use it in GitHub Desktop.
URL Parameter-based HTML Content Replacement with Clearbit
<script>
//extract all url parameters
function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [null, ''])[1].replace(/\+/g, '%20')) || null;
}
//pull out interesting parameters
company = getURLParameter('company');
company_name = getURLParameter('company_name');
//conditionally replace HTML content and inject values from those parameters
if (company) {
$("#homepage_h1").html("<img class='logo' src='https://logo.clearbit.com/example.com?size=75'><span class='and'>+</span>&nbsp;<img class='partner-logo' src='https://logo.clearbit.com/" + company + "?size=75'"+ " onerror=this.src='https://www.website.com/fallbackimage.png'>");
$("#homepage_h3").html("Hello" + company_name + "!");
}
else
{}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment