Reputation: 1287
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
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