Monday 5 August 2013

JavaScript Display Current Time on Webpage or Website without Refreshing the webPage





Description:-

                        In this Example we Explain that How to Display Current time in webpage or our Website.

Here we use SetTimeout Function of the Javascript to call the Function every one second Continuosly so we can view the current time in our webpage.

SetTimeout():-
                  
                       using this Function you can call Function at specified Time. it can be called only once like after 2 second or 5 second.

for ex:-setTimeout(Foo, 2000);


When program is run at that time we fetch the current time by using toLocaleTimeString() function of Date.


toLocaleTimeString():-

                        this Function will return the Current time of our pc in which the program is run.


in this Example generally when user start the appplication at that time setTimeout() funaction will fetch the current time of the current syatem and we will call this setTimeout() function every 1 second so that will work same like watch in your application.

to show Example of How to Display Gridview Row Detail in Javascript Popup click here Display Gridview ARow Detail in Javascript Popup

to show Example of how to Redirect to another aspx page in javascript click here Redirect to another aspx page in javascript

to show example of how to create timer or display clock in javascript click here create timer or display clock in javascript

Code For Display Time in Webpage:-



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script type="text/javascript">
        function DisplayCurrentTime() {
            var dt = new Date();
            document.getElementById("lblcurrenttime").innerHTML = dt.toLocaleTimeString();
            window.setTimeout("DisplayCurrentTime()", 1000);
        }
</script>
</head>
<body onload="DisplayCurrentTime()">
<form id="form1" runat="server">
<div>
<h1>JavaScript Example for Display current time in webpage Continuesly .</h1>
<label id="lblcurrenttime" style=" font-weight:bold"></label>
</div>
</form>
</body>
</html>


1 comments:

  1. A nice article, but how to add the time into blogger blog ?

    ReplyDelete