iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Graphics & Design Discussion Forum Post your graphics design questions/comments/ideas in here. Ask questions, post tutorials, discuss trends and best practices. Sub-forum for website accessibility and usability.

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-11-2008, 12:01 PM
WebProWorld New Member
 
Join Date: Apr 2008
Posts: 4
judithm RepRank 0
Default preload img in javascript help

Hi,

Can someone help me in javascript with preloading images. I am using a template and I want to preload the images for each page. Here is an exemple of a page : Andrée Roy | Artiste-peintre

What I did as a compromise is to have the images preload in the index.htm. Andrée Roy | Artiste peintre | Décoratrice But if someone gets to the site without going through the index, it doesn’t work.

Please help.

Thanks
Reply With Quote
  #2 (permalink)  
Old 09-11-2008, 07:10 PM
deepsand's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2004
Location: Philadelphia, PA
Posts: 3,248
deepsand RepRank 9deepsand RepRank 9deepsand RepRank 9deepsand RepRank 9deepsand RepRank 9deepsand RepRank 9deepsand RepRank 9deepsand RepRank 9deepsand RepRank 9deepsand RepRank 9deepsand RepRank 9
Default Re: preload img in javascript help

Well, if they're loaded by one page only, and the visitor never loads that page, why would you expect the images to be displayed?
Reply With Quote
  #3 (permalink)  
Old 09-11-2008, 07:38 PM
DaveSawers's Avatar
WebProWorld Veteran
 
Join Date: Dec 2006
Location: Calgary, Alberta, Canada
Posts: 492
DaveSawers RepRank 3DaveSawers RepRank 3
Default Re: preload img in javascript help

Quote:
Originally Posted by deepsand View Post
Well, if they're loaded by one page only, and the visitor never loads that page, why would you expect the images to be displayed?
Because the cache loads the images and displays them when the first page is displayed and doesn't have to reload them when moving onto the next page.

Anyway, in the <body> tag, add an onload and the javascript, like:

Code:
<body onload="initialsetup()">

<script>
function initialsetup() {
    MM_preloadImages('img1.gif', 'img2.gif', 'etc');
}

function MM_preloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
</script>
__________________
Dynamic Software Development
www.activeminds.ca
Reply With Quote
  #4 (permalink)  
Old 09-11-2008, 07:44 PM
DaveSawers's Avatar
WebProWorld Veteran
 
Join Date: Dec 2006
Location: Calgary, Alberta, Canada
Posts: 492
DaveSawers RepRank 3DaveSawers RepRank 3
Default Re: preload img in javascript help

Quote:
Originally Posted by judithm View Post
Here is an example of a page : Andrée Roy | Artiste-peintre
Hmm. Red text on a black background. On other pages, grey text on a black background. I couldn't read it at all so I left the site right away. Yuk!
__________________
Dynamic Software Development
www.activeminds.ca
Reply With Quote
  #5 (permalink)  
Old 09-11-2008, 09:15 PM
deepsand's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2004
Location: Philadelphia, PA
Posts: 3,248
deepsand RepRank 9deepsand RepRank 9deepsand RepRank 9deepsand RepRank 9deepsand RepRank 9deepsand RepRank 9deepsand RepRank 9deepsand RepRank 9deepsand RepRank 9deepsand RepRank 9deepsand RepRank 9
Default Re: preload img in javascript help

Quote:
Originally Posted by DaveSawers View Post
Because the cache loads the images and displays them when the first page is displayed and doesn't have to reload them when moving onto the next page.
How do they get cached if, per the OP, the visitor never loads the page which references the images?
Reply With Quote
  #6 (permalink)  
Old 09-17-2008, 02:18 PM
WebProWorld New Member
 
Join Date: Sep 2003
Location: glasgow,scotland
Posts: 12
iainrstewart RepRank 0
Default Re: preload img in javascript help

Regarding judithm (preload img in JavaScript help):-

I assume that you are referring to a second set of images to be used in html event handlers such as onmouseover, onmousedown etc.

All other images which are part of the page get downloaded anyway without any action on your part.

To have a browser download another set, you can use the following JavaScript conditional if statement:-

if(document.images){
var clickme1=new Image(100,30);clickme1.src="";
var clickme2=new Image(100,30);clickme2.src="";
var clickme3=new Image(100,30);clickme3.src="";
var clickme4=new Image(100,30);clickme4.src="";
var clickme5=new Image(100,30);clickme5.src="";
var clickme6=new Image(100,30);clickme6.src="";
var clickme7=new Image(100,30);clickme7.src="";
var clickme8=new Image(50,30);clickme8.src="";
var clickme9=new Image(50,30);clickme9.src="";
var clickme10=new Image(50,30);clickme10.src="";
var clickme11=new Image(100,30);clickme11.src="";
var clickme12=new Image(100,30);clickme12.src="";
}

The name which I show clickme1 is the name that I use in my own site to store a second image. You can use whatever name that you wish to use to name the var (storage container). Create a new var for each image. In the clickme1.src double quotes will be the name of the image to be stored. In the first statement the numbers in brackets after new Image is the size of the image in pixels ie 100px width and 30px height. These figures happen to be the figures appropriate to some of my images on my site. You will have to make the changes appropriate to your site images.

eg var next_image_one=new Image(85,40);next_image_one.src="this_is_it.gif";

Put the above if conditional statement in a separate script file which you appropriately name and in the head of every page source code put a reference to the separate script file. This will cause every page to download the image files.

For example, the script file could be named other_images.js and the reference in the head of every page would be:-

<script type="text/JavaScript" src="other_images.js"></script>

Iain R Stewart (excarex@yahoo.co.uk)
Reply With Quote
  #7 (permalink)  
Old 09-18-2008, 11:20 AM
WebProWorld New Member
 
Join Date: Apr 2008
Posts: 4
judithm RepRank 0
Default Re: preload img in javascript help

Thanks DaveSawers and iainrstewart.

Judith
Reply With Quote
Reply

  WebProWorld > Site Design > Graphics & Design Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
AJAX and javascript calling javascript krnl Web Programming Discussion Forum 14 11-18-2007 11:00 AM
Help with javascript... beka Graphics & Design Discussion Forum 4 02-20-2006 07:04 PM
Javascript + RSS + RSS = ? ofoglada Web Programming Discussion Forum 6 02-05-2006 06:33 AM
javascript souvik das Submit Your Logo For Review 2 02-25-2005 11:40 AM
JavaScript Help Dragonsi Web Programming Discussion Forum 12 05-29-2004 05:30 AM


All times are GMT -4. The time now is 03:23 AM.



Search Engine Optimization by vBSEO 3.3.0