ramazan murat
ramazan murat

Reputation: 1287

web page loading time

var startTime = new Date().getTime();
var myWin = window.open("http://www.hizlial.com/hediyelik/hediyelik-urunler/zippo-jack-daniels-ltr-flask-hediye-seti_16.004.4126.1233.htm","_blank")
window.onload = function() { opener.window.endtime = new Date().getTime(); }
var endTime = opener.window.endtime;
var timeTaken = endTime-startTime;
document.write(timeTaken);

i edited the new code but this time i couldnt write the timeTaken value? so whats wrong here?

Upvotes: 1

Views: 658

Answers (4)

qwertymk
qwertymk

Reputation: 35344

That's because javascript isn't a threaded language, meaning that it doesn't wait for things to happen, it will open the page and while the page is loading will go on and do other stuff. What you would need to do is to add this into the target page:

window.onload = function() { window.opener.endtime = new Date().getTime(); }

Or as ramazan murat wrote:

var startTime = new Date().getTime(); var myWin = window.open("www.mozilla.com");
window.onload = function() { opener.window.endtime = new Date().getTime(); };
var timeTaken = endTime-startTime;

Another way to go about this would be to do this:

<script>start = new Date().getTime();</script>
<iframe src="http://www.mozilla.com/" onload="end=new Date().getTime();"></iframe>

Upvotes: 1

wsanville
wsanville

Reputation: 37516

If you don't need to do this programmatically, then Firebug's Net tab will give you all the information you need to know about how long given resources on a page take to request.

Upvotes: 0

cbp
cbp

Reputation: 25628

Use Google Chrome's developer tool's timeline function.

Upvotes: 0

matthewpavkov
matthewpavkov

Reputation: 2928

I would use Net in Firebug to test a page's load time.

Upvotes: 0

Related Questions