Here is the code:
function getTime(j){
var stopClock= new Date();
delta[parseInt(j)]=stopClock.getMilliseconds()-start.getMilliseconds();
}
//REST OF THE CODE!!
function func(){
{
for (var i = 0; i < 6; i++){
start = new Date();
document.write('<img src="'+URL[i]+'" width="1" height="1" alt="" onload="getTime('+i+');"/>');
}
}
//SOME CODE
setTimeout(function() {
func();
},100);
However I got this error: getTime is not defined
if I declare getTime like this:
document.getTime= function (j)
There is no error but it never execute that function.
If I remover the setTimeout, it will work with no problem.
Any thoughts?
Thanks,
You’re destroying the DOM with your
document.writecall. In some browsers, this also destroys global variables.Instead of
document.write, try…Here’s a simple demonstration of the globals being cleared…
In Firefox, the second alert will be
undefined. In Chrome, the global is retained.http://jsfiddle.net/Z9NbR/