Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | JavaScript | Image | Q282 [ previous next ]

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

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?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.