www.webdeveloper.com
Results 1 to 3 of 3

Thread: Need help in following code!

  1. #1
    Join Date
    Jun 2005
    Posts
    64

    Question Need help in following code!

    i want to get the time at which page started loading and time at which it finishes loading.
    i have written the following code.in the code i want to add componenets in the body and note the time at which components starts loading.the component is the functionaliy which takes time for loading.can you plaese help me to modify the code ,i dont understand how to note the starttime for the components in the body?
    can anybody show it by taking simple elements(or forms buttons etc) in the body as the exapmle.

    <html>
    <head>
    <script type="text/javascript">
    var start = new Date();
    function timeIt()
    {
    var end = new Date();
    var difference = end.getTime() - start.getTime();
    document.write("This timestamp is"+difference+"ms")
    }
    </script>
    </head>

    <body onload="timeIt()">
    </body>
    </html>

  2. #2
    Join Date
    Dec 2004
    Posts
    8,637
    You cannot capture load timing for each component because all components do not have an onload event. Just for playing around purposes, though, you can spread code like this throughout your BODY section to capture timings at different points:
    Code:
    <script type="text/javascript">
    <!--//
    step1 = new Date();
    //-->
    </script>
    Code:
    <script type="text/javascript">
    <!--//
    step2 = new Date();
    //-->
    </script>
    Code:
    <script type="text/javascript">
    <!--//
    step3 = new Date();
    //-->
    </script>
    etc.

  3. #3
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    Set one date/time in a Javascript at the top of the head section of your page. Set the second at the end of the onload event on the body tag. The difference should be less than the load time for the page but as close to it as you can calculate with Javascript.
    Stephen

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles