Last active
December 15, 2022 11:42
-
-
Save johnnyopao/45cfa24597bc5577425c to your computer and use it in GitHub Desktop.
Pass URL parameters to Unbounce links containing Anchors
This file contains hidden or 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> | |
$(function() { | |
$('.lp-pom-image a, .lp-pom-text a, .lp-pom-button').not('a[href^=#]').each( function() { | |
var currentURL = this.href; | |
var hashIndex = currentURL.indexOf("#"); | |
var hasAnchor = hashIndex > -1; | |
var hashString = ""; | |
var baseURL = this.href; | |
if (hasAnchor) { | |
hashString = currentURL.substring(hashIndex); | |
baseURL = currentURL.substring(0, hashIndex); | |
} | |
var params = window.location.search; | |
var hasParameters = baseURL.indexOf("?") > -1; | |
if (hasParameters) { | |
params = params.replace('?', '&'); | |
} | |
this.href = baseURL + params + hashString; | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment