troubleshooting Question

Preloading images that are created from a PHP file

Avatar of mcravenufo
mcravenufo asked on
12 Comments1 Solution348 ViewsLast Modified:
I'm using a PHP file (image.php) that is dynamically creating images. It's final line output is:

I want to preload the images in my Javascript/HTML file but when I use the PHP file as the image source, the images do not preload. It appears to run the php code every time.

My preload Javascript:
<SCRIPT language="javascript">
var customImage1 = new Image(400, 300);
var customImage2 = new Image(400, 300);

customImage1 .src = "image.php?focus=1";
customImage2 .src = "image.php?focus=2";

<P><IMG src="image.php?focus=1" width="400" height="300" name="dynImage"></P>

So when I change the image source in my Javascript code because of some sort of user input, the image reloads every time:

// image reloads even though I've done the standard preload method
if($something == $another)
      document.dynImage.src = customImage1.src;
      document.dynImage.src = customImage2.src;

Is there a way to preload images that are created and returned from a PHP file?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 12 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros