Tuesday, November 11, 2014

Auto Copyright Year Javascript

In order to avoid visitors to see outdated copyright information or having someone to help out updating the copyright year on every new year, a simple Javascript can do the job easily. Here is an example of how it is done in a simple web page with a dummy copyright text:


<html>
<body>

© copyright 2007-<span id=currentYear>2013</span>. All rights reserved.

<script>
 var thisYear = new Date().getFullYear();
 document.getElementById('currentYear').innerHTML = thisYear;
</script>

</body>
</html>


Note: Make sure the Javascript is placed after the SPAN tag or you'll get an error for not being to find the 'currentYear' element.

Now you can sit back and relax during new year every year!

1 comment: