0

I am trying to display today's date in the title of my webpage. However, I tried to use the script below but it did not work. The script works in the body of the page. Is there different script I should use?

<script><!-- 
var dayNames = new Array("Sunday","Monday","Tuesday","Wednesday",
                "Thursday","Friday","Saturday");
var monthNames = new Array(
"January","February","March","April","May","June","July",
"August","September","October","November","December");
var now = new Date();
document.write(dayNames[now.getDay()] + ", " + 
monthNames[now.getMonth()] + " " + 
now.getDate() + ", " + now.getFullYear());

// -->
</SCRIPT>
Jaync31
  • 27
  • 8
  • Try looking at this similar question: http://stackoverflow.com/questions/413439/how-to-dynamically-change-a-web-pages-title – Chase Apr 26 '14 at 22:40

1 Answers1

1

Try

document.title=new Date();

You can also keep most of your old script, and change the part with document.write( stuff ); to document.title = stuff;

Paul
  • 23,002
  • 11
  • 77
  • 112