JavaScript implements a way to display the current date on the title bar

  • 2020-05-17 04:45:55
  • OfStack

This article demonstrates how the JavaScript implementation displays the current date on the title bar. Share with you for your reference. The specific implementation method is as follows:

<script language="JavaScript">
<!--
function writeIt() {
// getDate
var now = new Date();
var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();
// quadYear
function y2k(number){return (number < 1000) ? number + 1900 : number;}
// glueIt
today =  days[now.getDay()] + " " +
               months[now.getMonth()] + ", " +
                date + " " +
                (y2k(now.getYear())) ;
   if(document.all || document.getElementById){ // Browser Check
      document.title = today.toString();
   }else{
      self.status = today.toString(); // Default to status.
   }
}
writeIt();
//-->
</script>

I hope this article has been helpful to your javascript programming.


Related articles: