Reputation: 1295
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
Upvotes: 1
Views: 1631
Reputation: 235
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.
Upvotes: 0
Reputation: 14468
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()
Upvotes: 9