For my sites and web applications, as well as the ones I develop for my clients, I want to keep the copyright message fresh. It at least keeps up a pretense of someone updating the site once a year . And there’s no easier way to do it then with JavaScript.
All you need to do is locate the line in your footer that looks like:
<footer>copyright © 2009</footer>and replace the year with a
<span>
:<footer>copyright © <span id="year"></span></footer>And add this script tag to the end of the page:
<script> document.getElementById('year').textContent = (new Date()).getFullYear(); </script>Even easier: if your site is using jQuery, add this to the
ready
event: $('#year').text((new Date()).getFullYear());This way, your copyright message will always show the current year. Keeping your content fresh? Well, that’s up to you .
Update:
Here's a shorter way to achieve the same effect, with one line:
<footer>copyright © <script>document.write((new Date()).getFullYear());</script></footer>
[This way is also more efficient, since no DOM selection is taking place].
No comments:
Post a Comment
I enjoy all comments - unless they're spam. If you want to push a product/service/site - this is not the forum.