Keep copyright notice updated on your website – javascript

You must have seen the copy right notice or the copy right sign with year and company name on websites, generally at the very bottom of website page, like below:

Copyright ©1987-2008
© 2008 Microsoft
© 2006–2008 Cleartrip Travel Services Private Limited

The little but quite important problem we are going to solve here is to keep the year updated on the textual clause of copyright. This can be solved with javascript below. You can include it in some common javascript file (which is recommended because copyright is generally displayed on all the pages) or you can use it individually on pages.

 
function updateYear() {
  var cpyrt = document.getElementById("copyright")
  if (cpyrt) {
     cpyrt.firstChild.nodeValue = (new Date()).getFullYear();
  }
}
 

Call the function above while page loads.

 
window.onload = updateYear();
 

Include following HTML in your page at the bottom (footer).

 
Copyright © 2002-<span id="copyright">...</span> by Your company Name. All rights reserved
 

Most Commented Posts

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

No comments yet.

Leave a comment

(required)

(required)