web page loading time
var startTime = new Date().getTime();
v开发者_StackOverflow中文版ar 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?
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>
I would use Net in Firebug to test a page's load time.
Use Google Chrome's developer tool's timeline function.
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.
精彩评论