Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> JavaScript >> Snippet

Preload images


images can be kept in a page, invisible, by loading them into a JavaScript variable
that is delcared as an image object

var HiddenImage = new Image()
HiddenImage.src = "myPicture.jpg"

You can use the hidden image to set the property of a visible < img > control.

Create a normal < img > tag :

< img src = "differentPicture.jpg" name = "theImage" >

Then change it 's image with JavaScript

document.theimage.src = HiddenImage.src