Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, Could you please suggest me h 1

Status
Not open for further replies.

rcsen

Programmer
Jan 11, 2001
51
US
Hi,
Could you please suggest me how to calculate the load time of a particular webpage? I haven't used JavaScript before.

Ex: Time for a Registration page of Website to load.

Any help is appreciated.
Thanks
RCSEN
 
Try this...
Code:
<html>
<script language=&quot;javascript&quot;>
	var dte = new Date()
	var timeStart = dte.getTime()
	
	function CalcTime(){
		var dte = new Date()
		var diff = dte.getTime() - timeStart;
		var sec = diff/1000;
		var ms = diff/100;
		alert(&quot;Time to complete page load:\n   Seconds: &quot; + sec + &quot;\nMilliseconds: &quot; + ms);
		return true;
	}
		
</script>
<body onLoad=&quot;CalcTime()&quot;;>
<!--your code goes here-->
</body>
</html>
Hope it helps, Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
Thanks Mr.Rob,

I'll try this and let you know the results.

Sincerely,
RCSEN
 
To RobSchultz
Do I read correctly from your answer that the &quot;onload&quot; instructions are executed AFTER all the code is loaded?
Regards, Helmut
 
Hi Robschultz,
Thanks. That works fine. But, can I generealize it?
(ie) Can I pass the URL's as parameters, so that I can calculate the loading time for each separately?
Please let me know your suggestion.

RCSEN
 
engcomp:

Yes the onLoad event fires after all code within the body tags finishes loading.

rcsen:

Your wish is my command (IE 4+ only though you may be able to use ILAYER in NN)...
Code:
<html>
<script language=&quot;javascript&quot;>
    var dte = new Date()
    var timeStart = dte.getTime()
        
    function CalcTime(){
        var dte = new Date()
        var diff = dte.getTime() - timeStart;
        var sec = diff/1000;
        var ms = diff/100;
        alert(&quot;Time to complete page load:\n   Seconds: &quot; + sec + &quot;\nMilliseconds: &quot; + ms);
        return true;
    }
</script>
<body>
	<iframe id=&quot;ifTimer&quot; src=&quot;timed.html&quot; onLoad=&quot;CalcTime();&quot;></iframe>
</body>
</html>
Hope it helps, Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
Hi Rob,
The code calculates perfectly. Thanks. But at times,it displays two alert boxes if I specify a absolute path with different two elapsed timings. Also, the requirement has changed. I am to update the timings in a table. Can I do that Javascript or ???
Suggest me.

Thanks.
RCSEN.
 
rcsen,

I'm not sure what you mean by the first statement but as for the table question... Of course!...
Code:
<html>
<body>
	<table border=1 width=75% align=center>
		<tr>
			<td colspan=2 align=center><b>Page Load Timer</b></td>
		</tr>
		<tr>
			<td width=30%>Page name:</td>
			<td width=70% id=timerPage align=center>unknown</td>
		</tr>
		<tr>
			<td>Seconds:</td>
			<td id=timerSec align=center>processing...</td>
		</tr>
		<tr>
			<td>Milliseconds:</td>
			<td id=timerMS align=center>processing...</td>
		</tr>
	</table>
	<p align=center>
		<iframe style=&quot;visibility=hidden;&quot; id=ifTimer src=&quot;iftimed.html&quot; onLoad=&quot;CalcTime();&quot;></iframe>
	</p>
</body>
<script language=&quot;javascript&quot;>
    document.all.timerPage.innerText = document.all.ifTimer.src
    
    var dte = new Date()
    var timeStart = dte.getTime()
            
    function CalcTime(){
        var dte = new Date()
        var diff = dte.getTime() - timeStart;
        var sec = diff/1000;
        var ms = diff/100;
        document.all.timerSec.innerText = sec;
        document.all.timerMS.innerText = ms;
        return true;
    }
</script>
</html>

Remove style=&quot;visibility=hidden;&quot; to see the IFRAME.

Later, Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
Hi Rob,
My first statement means that when I enter the url as
it gives the load time with a single alert box.

But if I do the same as,
I get two alert boxes.
Thats it.
Also, I couldn't find &quot;onLoad&quot; in &quot;iframe&quot; in any of the materials available. If I am not wrong, this should be in the BODY TAG.
Can I pass the data to a database?

Sincerely,
RCSEN
 
This doesn't seem to be a problem within the tables version as I tried and it worked fine. It may be that the test page is being redirected but, again, the tables version works fine.

You may need to upgrade to the latest version of IE 5 (follow link above) as I tried it on IE 5.0 and the IFRAME onLoad event wasn't recognized. I don't know in which version of IE 5 that the IFRAME onLoad event started working but IE 5.5 works great.

discusses the properties of the IFRAME object. Look in the events section.

Yes, you can put these results into a database. You will need some sort of webserver with server-side scripting (IIS, Apache, whatever). This is a totally different discussion though. If you have IIS with ASP (or Apache with PHP) then you should submit a question to their respective forums on the tek-tips site.

Later, Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
Hi,
Is it possible to call a perl function using JAVASCRIPT. If possible, please elaborate how to go about.
Thanks.
RCSEN.
 
No client-side script can directly call server-side functions. You have to submit the page to your webserver and have the next server-side page handle the data. You can use CGI or ASP or PHP or JSP or anything else your heart desires that can communicate to your backend database. Go to this page to learn about forms then come back to this site with a new message thread asking for help with scripting related to your particular webserver/database.

-Rob Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top