473,881 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
+ 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.image s)
{
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 2341
> if (document.image s)

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

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.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Sep 14 '05 #3

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

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.image s)
{
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,2 65';
I[1] = 'pic2.jpg,300,2 25';
// etc

var im = 0;
var S = new Array();

function store_pics() {
if (document.image s) {
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\nret ry');
}
</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.image s)

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.image s)

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******* *************@c omcast.com...
Zoe Brown said the following on 9/14/2005 6:24 AM:
if (document.image s)
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*******@notq uitecorrectfree uk.com> wrote in message
news:5i******** *************** *********@4ax.c om...
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.image s)
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******** ************@co mcast.com...
Zoe Brown said the following on 9/14/2005 6:24 AM:
if (document.image s)

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

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

Similar topics

21
10235
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 rendering of <pre> in a fixed width font. To change that I'd have to specify a proportional font family, thereby falling into the size pitfall that is associated with any sort of author specified font family: a) If I specify a sans serif font...
3
3802
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 element, IE6 extends the element to contain the line. Both necessitate horizontal scrolling. 1) Is one considered incorrect, or are both fair interpretations of the recommendation?
7
18545
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 solid; color:red;
2
2800
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 do this in CSS? <STYLE TYPE="text/css"> pre{ font-size:xx-large;
5
24121
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) than standard text. I would like all of my text to be formatted this way, though I don't want to use the <pre> tag for all of it. Can anyone tell me what font and size are used by default for the <pre> tag? I don't want to change it's...
5
718
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 preserve formatting (white space and line feeds). However, this is not true when doing the same with the <code> tag listing (it will all be pasted on one line with multiple successive spaces treated as a single space) despite the fact that...
8
3880
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
2756
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 tags will remain making the page safe (I have to convert the linefeeds to <BR>s because the Server.EncodeHTML does not do that it seems). The problem is that users can use a special tag when editing the top to specify an area of the tip that will...
9
5561
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 shell pieces like this: <pre><code> #!/bin/sh ftp -i -n ftp.server.com&lt; &lt;EOF user username password epsv4 cd /
23
3663
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 so-called pre-fix notation or algebraic notation. Algebraic notations have the concept of operators, meaning, symbols placed around arguments. In algebraic in-fix notation, different
0
11097
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10814
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10400
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7953
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5781
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4597
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 we have to send another system
2
4196
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3223
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.