Created
April 4, 2018 20:05
-
-
Save danahmadi/483cb8b4d24a2ea06acb73c68adeb145 to your computer and use it in GitHub Desktop.
URL Parameter-based HTML Content Replacement with Clearbit
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> | |
//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> <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