473,473 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

pre-loading images not working?

Hello

I have following type of code in the header

function pre_load_pics()
{
if (document.images)
{
var image1 = new Image(400,265);
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?

Cheers

Geoff
Sep 14 '05 #1
15 2306
> if (document.images)

what is this ?
Sep 14 '05 #2
Zoe Brown said the following on 9/14/2005 6:24 AM:
if (document.images)

what is this ?


It is a test to see if the browser supports the document.images
collection, when the test should be window.Images

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Sep 14 '05 #3

"Randy Webb" <Hi************@aol.com> wrote in message
news:LY********************@comcast.com...
Zoe Brown said the following on 9/14/2005 6:24 AM:
if (document.images)

what is this ?


It is a test to see if the browser supports the document.images
collection, when the test should be window.Images


Thats what I thought, so Geoff this value will be false and this code is
simply not executing, hence why your images are not being loaded...

you could have tried to debug this yourself and put in an alert to check
that your code was being hit !
Sep 14 '05 #4
ASM
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
Sep 14 '05 #5
On Wed, 14 Sep 2005 06:56:56 -0400, Randy Webb
<Hi************@aol.com> wrote:
Zoe Brown said the following on 9/14/2005 6:24 AM:
if (document.images)

what is this ?


It is a test to see if the browser supports the document.images
collection, when the test should be window.Images


Randy,

OK - I have changed to window.Images but still the images are not
downloaded at the beginning! Why is this?

Cheers

Geoff

Sep 14 '05 #6
ASM
Zoe Brown wrote:
if (document.images)

what is this ?


the img collection of page

as you have

document.forms
document.links
--
Stephane Moriaux et son [moins] vieux Mac
Sep 14 '05 #7
On Wed, 14 Sep 2005 10:56:59 GMT, "Zoe Brown"
<zo***********@N-O-S-P-A-A-Mtesco.net> wrote:

"Randy Webb" <Hi************@aol.com> wrote in message
news:LY********************@comcast.com...
Zoe Brown said the following on 9/14/2005 6:24 AM:
if (document.images)
what is this ?


It is a test to see if the browser supports the document.images
collection, when the test should be window.Images


Thats what I thought, so Geoff this value will be false and this code is
simply not executing, hence why your images are not being loaded...

you could have tried to debug this yourself and put in an alert to check
that your code was being hit !


I take your point Zoe, but having changed to window.Images the images
are still not being downloaded at the beginning - will try an alert()!

Cheers

Geoff
Sep 14 '05 #8

"Geoff Cox" <ge*******@notquitecorrectfreeuk.com> wrote in message
news:5i********************************@4ax.com...
On Wed, 14 Sep 2005 06:56:56 -0400, Randy Webb
<Hi************@aol.com> wrote:
Zoe Brown said the following on 9/14/2005 6:24 AM:
if (document.images)
what is this ?


It is a test to see if the browser supports the document.images
collection, when the test should be window.Images


Randy,

OK - I have changed to window.Images but still the images are not
downloaded at the beginning! Why is this?


I am wondering how you *know* they are not being downloaded ?

Please stick that alert in and check that your code is doing something
please.
Sep 14 '05 #9
ASM
Zoe Brown wrote:
"Randy Webb" <Hi************@aol.com> wrote in message
news:LY********************@comcast.com...
Zoe Brown said the following on 9/14/2005 6:24 AM:
if (document.images)

what is this ?
It is a test to see if the browser supports the document.images
collection, when the test should be window.Images


Thats what I thought, so Geoff this value will be false and this code is
simply not executing, hence why your images are not being loaded...


but as every non-text navigator understand : document.images ...
you could have tried to debug this yourself and put in an alert to check
that your code was being hit !


no it is not this condition which breaks the function

it is overall because the images and images.src are stored in volatile variables
--
Stephane Moriaux et son [moins] vieux Mac
Sep 14 '05 #10
ASM
Geoff Cox wrote:
On Wed, 14 Sep 2005 06:56:56 -0400, Randy Webb
<Hi************@aol.com> wrote:

Zoe Brown said the following on 9/14/2005 6:24 AM:

if (document.images)
what is this ?


It is a test to see if the browser supports the document.images
collection, when the test should be window.Images

Randy,

OK - I have changed to window.Images but still the images are not
downloaded at the beginning! Why is this?


see my other posts ... (above)

--
Stephane Moriaux et son [moins] vieux Mac
Sep 14 '05 #11
On Wed, 14 Sep 2005 10:56:59 GMT, "Zoe Brown"
<zo***********@N-O-S-P-A-A-Mtesco.net> wrote:

"Randy Webb" <Hi************@aol.com> wrote in message
news:LY********************@comcast.com...
Zoe Brown said the following on 9/14/2005 6:24 AM:
if (document.images)
what is this ?


It is a test to see if the browser supports the document.images
collection, when the test should be window.Images


Zoe,

I think I see the problem - the images are being dwonloaded but I am
confusing the situation in the way I am loading them later in the
program...

I have

function pre_load_pics()
{
if (window.Images)
{
alert(window.Images);
var image1 = new Image(400,265);
image1.scr = "pic1.jpg";
var image2 = new Image(400,265);
image2.scr = "pic2.jpg";

etc

but then also

var picture = new Array(7);
picture[0] = "pic1.jpg";
picture[1] = "pic2.jpg";
picture[2] = "pic3.jpg";
picture[3] = "pic4.jpg";

so that I can refer to the pics as picture[situation_number]

How do I correct this?

Cheers

Geoff


Sep 14 '05 #12
On Wed, 14 Sep 2005 11:28:17 GMT, Geoff Cox
<ge*******@notquitecorrectfreeuk.com> wrote:
I think I see the problem - the images are being dwonloaded but I am
confusing the situation in the way I am loading them later in the
program...


Nope, how you refer to a url in script makes no difference.

document.images is perfectly fine, window.Image would also be fine,
window.Images probably not, however your problem is almost certainly
dealt with in the FAQ http://jibbering.com/faq/#FAQ4_31

Jim.
Sep 14 '05 #13
ASM
Geoff Cox wrote:
Zoe,

I think I see the problem - the images are being dwonloaded but I am
confusing the situation in the way I am loading them later in the
program...


not only :
- you use volatile variables
- pre load function use real url
- the array of images is not used in this function

see my other post :
'Re: pre-loading images not working'
Wed, 14 Sep 2005 13:14:41 +0200
<43**********************@news.wanadoo.fr>

where array of images is used

and it is not important if array of images is set in end of page
if you start the post-loader-function after page is loaded
(and if you don't try to use them during loading ... of course !)

--
Stephane Moriaux et son [moins] vieux Mac
Sep 14 '05 #14
On Wed, 14 Sep 2005 11:40:51 GMT, ji*@jibbering.com (Jim Ley) wrote:
On Wed, 14 Sep 2005 11:28:17 GMT, Geoff Cox
<ge*******@notquitecorrectfreeuk.com> wrote:
I think I see the problem - the images are being dwonloaded but I am
confusing the situation in the way I am loading them later in the
program...


Nope, how you refer to a url in script makes no difference.

document.images is perfectly fine, window.Image would also be fine,
window.Images probably not, however your problem is almost certainly
dealt with in the FAQ http://jibbering.com/faq/#FAQ4_31

Jim.

Jim and others - thanks for all your comments..

Cheers

Geoff
Sep 14 '05 #15
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);
image1.scr = "pic1.jpg";
var image2 = new Image(400,265);
image2.scr = "pic2.jpg";

etc etc

}


Perhaps you mean "image1.src", not "image1.scr"
Mick

Sep 14 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Headless | last post by:
I've marked up song lyrics with the <pre> tag because it seems the most appropriate type of markup for the type of data. This results in inefficient use of horizontal space due to UA's default...
3
Pre
by: Neal | last post by:
A few questions about pre... When presenting preformatted text using the white-space: pre; property/value, Opera renders long lines at small viewport widths as exiting the borders of the...
7
by: Alan Illeman | last post by:
How do I set several different properties for PRE in a CSS stylesheet, rather than resorting to this: <BODY> <PRE STYLE="font-family:monospace; font-size:0.95em; width:40%; border:red 2px...
2
by: Buck Turgidson | last post by:
I want to have a css with 2 PRE styles, one bold with large font, and another non-bold and smaller font. I am new to CSS (and not exactly an expert in HTML, for that matter). Is there a way to...
5
by: Porthos | last post by:
I'm authoring an XML document and using the <pre> html tag for the portions that are not dynamically generated. The <pre> text is displaying in a smaller font size (and I believe different font)...
5
by: Michael Shell | last post by:
Greetings, Consider the XHTML document attached at the end of this post. When viewed under Firefox 1.0.5 on Linux, highlighting and pasting (into a text editor) the <pre> tag listing will...
8
by: Jarno Suni not | last post by:
It seems to be invalid in HTML 4.01, but valid in XHTML 1.0. Why is there the difference? Can that pose a problem when such a XHTML document is served as text/html?
7
by: Rocky Moore | last post by:
I have a web site called HintsAndTips.com. On this site people post tips using a very simply webform with a multi line TextBox for inputing the tip text. This text is encode to HTML so that no...
9
by: Eric Lindsay | last post by:
I can't figure how to best display little snippets of shell script using <pre>. I just got around to organising to bulk validate some of my web pages, and one of the problems occurs with Bash...
23
by: Xah Lee | last post by:
The Concepts and Confusions of Pre-fix, In-fix, Post-fix and Fully Functional Notations Xah Lee, 2006-03-15 Let me summarize: The LISP notation, is a functional notation, and is not a...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.