473,241 Members | 1,632 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,241 software developers and data experts.

Question about Preloading images

Is this the correct way to preload an image...?

Var Image1 = new Image()

....And then when I'm ready to use the image I can do this...?

Button1.src=Image1.src

....Or am I just telling Button1 to use the same source path as Image1?
Jul 23 '05 #1
6 1543
michaaal wrote:
Is this the correct way to preload an image...?

Var Image1 = new Image()
var is case sensitive, its lower-case v

And you have forgotten to define the src attribute to the new Image()
you just created.

Image.src='url to Image';
....And then when I'm ready to use the image I can do this...?

Button1.src=Image1.src

....Or am I just telling Button1 to use the same source path as Image1?


With the above additions, now you can.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #2
Randy Webb wrote:
michaaal wrote:
Is this the correct way to preload an image...?

Var Image1 = new Image()


var is case sensitive, its lower-case v

And you have forgotten to define the src attribute to the new Image()
you just created.

Image.src='url to Image';


Image1.src = ...
^
Otherwise a property would be added to the constructor.
....And then when I'm ready to use the image I can do this...?

Button1.src=Image1.src

....Or am I just telling Button1 to use the same source path as Image1?


With the above additions, now you can.


Yes, indeed :)

Yet it is not a very good way of preloading images, if there is some
(preloading should be done very careful -- not only that is is not really
required, it is unreliable [because my cache is *my* cache and client-side
scripting may be disabled/restricted/not present] and if it works it forces
users to download data they do not requested), it is unreliable,
error-prone and quite hard to maintain. I have been working on another
approach that does not show most of these problems:

<http://pointedears.de/scripts/test/hoverMe>
PointedEars
Jul 23 '05 #3
Thomas 'PointedEars' Lahn wrote:
Randy Webb wrote:

michaaal wrote:
Is this the correct way to preload an image...?

Var Image1 = new Image()


var is case sensitive, its lower-case v

And you have forgotten to define the src attribute to the new Image()
you just created.

Image.src='url to Image';

Image1.src = ...
^
Otherwise a property would be added to the constructor.


True, was a typo.
....And then when I'm ready to use the image I can do this...?

Button1.src=Image1.src

....Or am I just telling Button1 to use the same source path as Image1?


With the above additions, now you can.

Yes, indeed :)

Yet it is not a very good way of preloading images, if there is some
(preloading should be done very careful -- not only that is is not really
required, it is unreliable [because my cache is *my* cache and client-side
scripting may be disabled/restricted/not present] and if it works it forces
users to download data they do not requested), it is unreliable,
error-prone and quite hard to maintain. I have been working on another
approach that does not show most of these problems:

<http://pointedears.de/scripts/test/hoverMe>


If you want a non-script way of loading images:

<img src="theImage.jpg" width="1" height="1" alt="">

And its a 1 pixel dot on the page, but the image gets loaded, unless
images are disabled and then it doesn't really matter.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #4
Randy Webb wrote:
If you want a non-script way of loading images:

<img src="theImage.jpg" width="1" height="1" alt="">


That may be viable for graphical browsers,
not for other types of user agents.
PointedEars
Jul 23 '05 #5
Thomas 'PointedEars' Lahn wrote:
Randy Webb wrote:

If you want a non-script way of loading images:

<img src="theImage.jpg" width="1" height="1" alt="">

That may be viable for graphical browsers,
not for other types of user agents.


And why would you need to preload/cache images in a non-graphical user
agent?

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #6
Randy Webb wrote:
Thomas 'PointedEars' Lahn wrote:
Randy Webb wrote:
If you want a non-script way of loading images:

<img src="theImage.jpg" width="1" height="1" alt="">


That may be viable for graphical browsers,
not for other types of user agents.


And why would you need to preload/cache images in a non-graphical user
agent?


You would not but the display of those "img" elements intended merely for
preloading/caching could be disturbing anyway. Text browsers like lynx
or links, e.g., can be configured to display "img" elements as a link for
downloading the image resource as a file (to be displayed by user-defined
graphics viewer software, for example).
PointedEars
Jul 23 '05 #7

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

Similar topics

1
by: Brynn | last post by:
I know this isn't an ASP question ... but the knowledge in this group usually surpasses the rest, and I used to answer questions here all of the time, so anyway. Why all of this javascript and...
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...
2
by: Julie | last post by:
Hi, I'm trying to change images on a website without reloading the whole page and use the following code to preload the images: var preloadFlag = false; function preloadImages() { if...
2
by: windandwaves | last post by:
Hi Gurus Preloading images has got to be JS 101. However, it does not seem to be working. Here is the function that I am using. I added the alerts to make sure it is working and all the right...
40
by: Geoff Cox | last post by:
Hello, I am still having problems - apologies if the answer is in previous postings! I now have, in the header, <sctipt> var myimages=new Array();
9
by: peashoe | last post by:
I need to create a javascript that not only changes a picture, but also the link: here is an example of what I need www.myweddingfavors.com/ I'm working on this website and have it half done:...
7
by: Inny | last post by:
Hello again, Im using the code below in a child page (popup), the images are called from the parent page. When the changer is running, the child page goes white between images. I realise this is...
7
by: Keith Hughitt | last post by:
Hi all, I am having trouble preloading images in a javascript application, and was wondering if anyone had any suggestions. Basically I have a bunch of images stored in a database as BLOBs. At...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.