Created
July 24, 2014 20:07
-
-
Save neilhoff/e151c155235f96214750 to your computer and use it in GitHub Desktop.
Add a url param to all links on a 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
$(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 ? "¶m=" + paramToAdd : "?param=" + paramToAdd); | |
} | |
} | |
catch (err) { | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment