Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q282 How can I preload images into the browser cache, but only one at a time?

You are here: irt.org | FAQ | JavaScript | Image | Q282 [ previous next ]

The following will load images name image1.gif through to image9.gif one at a time for browsers that support the JavaScript image object:

<SCRIPT LANGUAGE="JavaScript"><!--
function next() { if (++no < 10) load(); }

function load() {
    img[no] = new Image();
    img[no].onload = next;
    img[no].src = 'image' + no + '.gif';
}

if (document.images) {
    var img = new Array(10), no = 1;
    load();
}
//--></SCRIPT>

Feedback on 'Q282 How can I preload images into the browser cache, but only one at a time?'

©2018 Martin Webb