Hi,
Hi,
Maybe I am explaining it wrong.
I am creating a custom control which given a list of images generates
the javascript code and add it to a page so the images are preloaded.
I want to use it in my master pages or in my pages.
Now i am looking for the right javascript code. Any ideas?
I also need to check if I can use it in a Master Page.
I know that I need to add the javascript code to the page. That's ok.
The problem is that I also need to add some code to the Html body tag.
Something like <body onload="...">
Any idea of how to do this?
Thanks,
Miguel
Here are a few hints to get you started.
You preload images in JavaScript using the Image object. You use the
onload event to check when an image is correctly fully loaded. You use
the onerror object to check when an error occurs (for example when an
image is not found.
The onload and onerror event handlers cannot take parameters. Either you
don't need them (for example, you decide that if one error occurs, then
the whole page is invalid), or you can use closure to pass parameters to
the handling function anyway.
Example:
var myImage = new Image();
myImage.onload = imageOnLoad;
myImage.onerror = imageOnError;
myImage.src = "myimage.gif"; // This is the line starting the request
with:
function imageOnLoad()
{
writeStatus( "One image loaded, only " + iImages-- + " to go..." );
}
function imageOnError()
{
alert( "Big problem" );
}
HTH,
Laurent