473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

document.images when prefetching images

When prefetching images, why do I need the "if (document.images)" statement?

if (document.images) {
pic1on= new Image(300,300);
pic1on.src="pic1.gif";
pic2on= new Image();
pic2on.src="pic2.gif";
picNon= new Image();
picNon.src="pic4.gif";
}
Jul 23 '05 #1
5 1811
So that browsers that don't support "document.images" won't blow chunks.

"Amir" <so*******@verizon.net> wrote in message
news:ct*******************@nwrdny02.gnilink.net...
When prefetching images, why do I need the "if (document.images)" statement?
if (document.images) {
pic1on= new Image(300,300);
pic1on.src="pic1.gif";
pic2on= new Image();
pic2on.src="pic2.gif";
picNon= new Image();
picNon.src="pic4.gif";
}

Jul 23 '05 #2
Ivo

"William Morris" topposted
So that browsers that don't support "document.images" won't blow chunks.

"Amir" asked
When prefetching images, why do I need the "if (document.images)"
statement?

if (document.images) {
pic1on= new Image(300,300);
pic1on.src="pic1.gif";
pic2on= new Image();
pic2on.src="pic2.gif";
picNon= new Image();
picNon.src="pic4.gif";
}


You don't. What you want is:
if(window.Image){...}
to prevent errors in browsers that don't understand what you mean by "new
Image()". Since practically all browsers today have no problem with the
Image object (nor with the only slightly related document.images collection)
you might as well drop this feature test altogether.
HTH
Ivo
Jul 23 '05 #3
In article <ct*******************@nwrdny02.gnilink.net>,
so*******@verizon.net enlightened us with...
When prefetching images, why do I need the "if (document.images)" statement?


Not all browsers support document.images (object). Trying to access it
would blow up unsupporting browsers (IIRC, Lynx has no such construct
nor do very old versions of netscape). The test returns true only for
browsers that have the object.
Basically, this is referred to as degrading gracefully (that is, the
code won't work "right" for unsupporting browsers, but it won't kill
them with errors, either).
All your code should have such constructs if you're coding for the
internet. You just don't know what browsers people are using. New
browsers come out frequently enough that browser detection is a horrid
idea (plus there's a lot you've probably never heard of). So, object
detection, which is what this is, is the better way to go.

--
--
~kaeli~
It was recently discovered that research causes cancer in
rats.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #4
Lee
William Morris said:

So that browsers that don't support "document.images" won't blow chunks.


Too late. They already do.

Jul 23 '05 #5
kaeli wrote:
In article <ct*******************@nwrdny02.gnilink.net>,
so*******@verizon.net enlightened us with...
Please do not write attribution novels, see
<http://netmeister.org/news/learn2quote.html>
When prefetching images, why do I need the "if (document.images)" statement?


Not all browsers support document.images (object). Trying to access it
would blow up unsupporting browsers (IIRC, Lynx has no such construct


Lynx supports J(ava)Script?
nor do very old versions of netscape). The test returns true only for
browsers that have the object. [...]


ACK
PointedEars
Jul 23 '05 #6

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

Similar topics

22
by: Fabian | last post by:
var preload1 = new Image(); preload1.src = "/pic/yay.gif"; var preload2 = new Image(); preload2.src = "/pic/nay.gif"; The above is meant to preload image files, yes? Problem is, it doesnt seem...
1
by: Winfried Koenig | last post by:
Hi everyone, I have a main page: -------------------------------------------------- <html><head><title>Test</title> </head><body> <img id="img_a" name="img_a" src="image_1.png" alt=""><br>
3
by: Pieter Van Waeyenberge | last post by:
Hello, im some image elements using doc.createElement('IMG'); i set the following styles: - for the images container: white-space:normal; - for the images themselves: display: inline; i...
10
by: Sean C. | last post by:
Helpful folks, I ran across a statement I found rather confusing in the IBM-published Advanced DBA Certification Guide and Reference for UDB V8. On page 107 the author is explaining why the a...
9
by: Jeff | last post by:
I get the following error when I try to rollover my button: document.images has no properties Line: 22 Am I doing this correctly? Suggestions? This is using Netscape 7.2 on Fedora core 4. ...
6
by: Bob Alston | last post by:
I am looking for others who have built systems to scan documents, index them and then make them accessible from an Access database. My environment is a nonprofit with about 20-25 case workers who...
4
by: dr1ft3r | last post by:
Hey guys, I'm building a site for a landscaping business down the street and can't seem to get part of the code functioning correctly. The code fails on line 68 where I make a reference to an...
10
by: AC | last post by:
I had a page that does some event setup on window.onload: function prepEvents() { document.getElementById("menumap_sales").onmouseover = swapMenuSales; // etc } window.onload = prepEvents;
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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,...
0
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...

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.