Skip to content

Instantly share code, notes, and snippets.

Created December 23, 2013 21:19
Show Gist options
  • Save anonymous/8104830 to your computer and use it in GitHub Desktop.
Save anonymous/8104830 to your computer and use it in GitHub Desktop.
A nice little javascript snippet to automatically inject the current year into anywhere you keep your copyright so that it stays up to date.
<!-- A fairly normal copyright stamp with placeholder for current year -->
<p>&copy; Copywright <span class="copyrightYear"></span>, All rights reserved.</p>
<!-- Copywright date injection -->
<script type="text/javascript">
(function() {
function injectCopywrightDate() {
var year = new Date().getFullYear();
var placeholders = document.getElementsByClassName('copyrightYear');
for(var placeholder in placeholders) {
if (placeholders.hasOwnProperty(placeholder)) {
placeholders[placeholder].innerText = year;
}
}
}
function onLoad(e) {
injectCopywrightDate();
}
// Handle browser inconsistency (cough.cough.IE..)
if (window.addEventListener) {
window.addEventListener('load', onLoad);
}
else if (window.attachEvent) {
window.attachEvent('onload', onLoad);
}
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment