Created
December 23, 2013 21:19
-
-
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.
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 fairly normal copyright stamp with placeholder for current year --> | |
<p>© 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