Created
October 17, 2021 18:37
-
-
Save camsloanftc/b2962c81b0069e290918a6ef1b0c9836 to your computer and use it in GitHub Desktop.
Jquery - Append current url params to all urls on page
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
$("a").each(function () { | |
$(this).attr( | |
"href", | |
function () { | |
var currentUrlHasNoParams = location.search == "" | |
var hrefAlreadyHasQueryString = $(this).attr("href").includes("?") | |
var token = hrefAlreadyHasQueryString ? "&" : "?" | |
if(currentUrlHasNoParams){ | |
return $(this).attr("href") | |
} | |
return $(this).attr("href") + token + location.search.substring(1) | |
} | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment