Skip to content

Instantly share code, notes, and snippets.

@johnnyopao
Last active December 15, 2022 11:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save johnnyopao/45cfa24597bc5577425c to your computer and use it in GitHub Desktop.
Save johnnyopao/45cfa24597bc5577425c to your computer and use it in GitHub Desktop.
Pass URL parameters to Unbounce links containing Anchors
<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