To access an image file in user computer you can use "Preloading". Preloading helps you to load an image file in the user computer. it’s very helpful like if you have a mouseover event and you want to change an image instantly, so it will help you to change an image
To preload same images on all the different pages use the below-given code. To start this first you have to add the given code in your main JavaScript file
After adding this code, when you call main java script then add following code given below in your <head> webpage.
NOTE: Replace your required file name in given code.
- Step 1: Simple and Nice
By using duplicating image line you can add more than one image in your script.
- Step2 : Flexible Array method:
To preload same images on all the different pages use the below-given code. To start this first you have to add the given code in your main JavaScript file
After adding this code, when you call main java script then add following code given below in your <head> webpage.
You can add as many images as you want but always separate them with using a comma.
NOTE: Replace your required file name in given code.
- Step3: without using JavaScript