473,322 Members | 1,719 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,322 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 1545
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...
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.