How to display the date and time when the page gets loaded?

 Posted by Kmandapalli on 3/3/2014 | Category: JavaScript Interview questions | Views: 1790 | Points: 40

<SCRIPT LANGUAGE = "Javascript">
var today= new Date() </SCRIPT>
<BODY onload=alert(today)>

In this, the event handler onLoad is embedded within the tag. OnLoad activates whenever a new page has finished downloading. This alert code tells the browser to create an alert box containing the value of the variable "today". Thus, it automatically prints out the date and time when the page has finished loading and requires no special action by the user.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response