473,769 Members | 1,618 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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=Ima ge1.src

....Or am I just telling Button1 to use the same source path as Image1?
Jul 23 '05 #1
6 1588
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=Ima ge1.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.javas cript 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=Ima ge1.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='ur l 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.j pg" 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.javas cript 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.j pg" 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.j pg" 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.javas cript 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.j pg" 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
1595
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 css image preloading. IE has picked up on the CSS hidden-preloading and doesn't see to pull the image if it is 'hidden' and the javascript way is ok
22
3137
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 to be doing so in practice. Any idea where Im going wrong? Could it be that things work differnetly when in an attached .js file? -- --
2
1903
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 (document.images) { pic_moon2_click = newImage("images/moonpic2.jpg"); pic_moon3_click = newImage("images/moonpic3.jpg");
2
1857
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 alerts show up, yet when I do my mouseover, it still takes about a second (only the first time) to load the image (thumbnail). Am I missing anything?
40
2847
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
1865
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: www.mygiftbasketideas.com - I also what the table to change color on mouseover - this is the code I am using so far: in the script.js if (document.images) { image2= new Image(100,100);
7
2456
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 happening because the Images are not cached (yet) on the users browser. I tried preloading images with the 2nd code below in the childpage head and in the parent page head and both. no joy, dosent seem to actually 'preload' the pics. (i also gave...
7
2000
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 any given point in time a subset of those images is displayed on- screen. At certains times I want to swap out those on screen with new ones from the database, and do some as seamlessly as possible. So what I've tried to do is first create Image...
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10211
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
7408
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
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
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
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3958
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
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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.