1

I have used Javascript onlaod like this:

function check()
{
   var pic =  new Image();
   pic.src= "images/first.jpg";
   pic.onload =  function()
   {
     alert("Uploaded");
   }
}

This is html code where the function is called.

<input type="button" onclick="check()" value="Check" />

It works for both safari and firefox. But with IE, first time it works but when I click on check Button next time it does not work. It also works when cache is cleared.

Can anyone help me what problem might occur here.

Thanks in advance

2 Answers 2

9

This should not be a problem in IE8.

IE6 (not sure about 7) is notoriously eager to use cached files, and when taking from the cache the load is not correctly calculated (I recall there being an interesting bug report on this, look for it on MS's site).

It can be solved by adding a [useless] parameter that forces a reload of the cached file:

pic.src= "images/first.jpg?nocache="+Math.random()

Sign up to request clarification or add additional context in comments.

2 Comments

A random parameter will solve the caching issue. Your case looks like a caching issue only.
Thank you so much samgoody and Faiz !!! Its just a cache problem. It's working now. Thanks again :)
0

perhaps the onload() is too early?

jquery uses a function

$(document).ready(function(){} 

that is executed when the page has finished loading. Perhaps you need some similar function.

1 Comment

OP is using the correct event handler, it is just IE aggressively caching and then not reporting a load event the 2nd-Nth times

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.