Preload image problems in ASP. NET

Source: Internet
Author: User
Javascript depends on the browser. It may be that IE 6 does not support your image pre-loading function.
You can refer to the following code to pre-load images using JavaScript:
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML>
<Head>
<Title> new document </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Script language = "JavaScript">
<! --
VaR Ie = navigator. appname = "Microsoft Internet Explorer ";
VaR opera = navigator. appname. tolowercase () = "Opera ";
VaR FF =! IE &&! Opera;
Function LoadImage (arrsrc, callback)
{
This. Length = arrsrc. length;
This. loadedlen = 0; // number of images already loaded
VaR self = this;
If (self. Length <1)
{
Callback (arrsrc );
Return;
}

// According to the test, the loading method of opera is different from that of other browsers, so it is particularly independent...
If (opera)
{
For (VAR I = 0; I <self. length; I ++)
{
VaR tmpimg = new image ();
Tmpimg. src = arrsrc [I];
Tmpimg. onload = function ()
{
Self. loadedlen ++;
If (self. loadedlen = self. Length & callback) callback (arrsrc );
}
}
Return;
}

This. load = function ()
{
Self. loadedlen ++;
Document. getelementbyid ("counter"). innerhtml = self. loadedlen;
If (self. loadedlen <self. Length) self. downimg ();
Else if (callback) callback (arrsrc );
}

This. downimg = function ()
{
VaR tmpimg = new image ();
Tmpimg. src = arrsrc [self. loadedlen];
If (IE)
{
If (tmpimg. readystate = "complete") self. Load ();
Else tmpimg. onreadystatechange = function ()
{
If (this. readystate = "complete") self. Load ();
}
}
Else tmpimg. onload = self. load;
}
This. downimg ();
}
// -->
</SCRIPT>
</Head>
<Body>
<Div id = "counter"> </div>
<Script language = "JavaScript">
<! --
VaR arr = ['HTTP: // response
VaR T = new LoadImage (ARR, function (ARR)
{

VaR STR = "";
For (VAR I = 0; I <arr. length; I ++)
{
STR + = " <br> ";
}
Document. Body. innerhtml + = STR;
});
// -->
</SCRIPT>
</Body>
</Html>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.