Skip to content

Instantly share code, notes, and snippets.

@neilhoff
Created July 24, 2014 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neilhoff/e151c155235f96214750 to your computer and use it in GitHub Desktop.
Save neilhoff/e151c155235f96214750 to your computer and use it in GitHub Desktop.
Add a url param to all links on a page
$(document).ready(function() {
var paramToAdd = "function called to fill this variable"
if (paramToAdd.length > 0) {
$("a").attr('href', function (i, h) {
//try catch needed for odd links(Ex: the slider nav squares when using Flexslider)
try {
var invalidLink = h.lastIndexOf("tel:", 0) === 0 || h.lastIndexOf("mailto:", 0) === 0;
if (!invalidLink) {
return h + (h.indexOf('?') != -1 ? "&param=" + paramToAdd : "?param=" + paramToAdd);
}
}
catch (err) {
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment