Geoff Cox wrote:
Hello
I have following type of code in the header
function pre_load_pics()
{
if (document.images)
{
var image1 = new Image(400,265);
no !
not var imag...
you need global variables
if not you'll can't call them !
image1.scr = "pic1.jpg";
var image2 = new Image(400,265);
image2.scr = "pic2.jpg";
etc etc
}
and the following in the body
<script>
pre_load_pics();
</script>
but images are not downloaded until the app needs them later.
Something wrong ? I thought they should be downloaded earlier?
try :
onload = pre_load_pics;
that would have to post load your images
.... if you don't click on page during loading
(look to your status bar)
anyway ...
your script is only a declaration giving shortcuts for some images
If navigator isn't too lazy or buzzy, perhaps will he store these
images in his cache
and ... of course you must wait complete post-load
before to use images from cache
You can try to force navigator to store images in its cache :
(not verified, and not sure IE and/or Opera will appreciate)
<script type="text/javascript">
var I = new Array();
I[0] = 'pic1.jpg,400,265';
I[1] = 'pic2.jpg,300,225';
// etc
var im = 0;
var S = new Array();
function store_pics() {
if (document.images) {
var sr = I[im].split(',');
var w = sr[1];
var h = sr[2];
S[i] = new Image(w,h);
S[i].onload = store_pics;
S[i].scr = sr[0];
im++;
}
}
onload = store_pics;
function show_i(imag) {
if(imag <= im)
document.images('here').src = S[imag].src;
else
alert('image not yet donwloaded\nretry');
}
</script>
<a href="pic1.jpg" target="myImage"
onclick="show_i(0);return false;">image 1</a>
<a href="pic1.jpg" target="myImage"
onclick="show_i(1);return false;">image 2</a>
<a href="pic1.jpg" target="myImage"
onclick="show_i(2);return false;">image 3</a>
<img name="here" src="">
--
Stephane Moriaux et son [moins] vieux Mac