Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jan 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Preload images then redirect

    Hi,

    Does anyone have a script which would allow me to preload some images into memory (without displaying), then redirect to another page AFTER all the images have finished loading?

    Thanks for any help.

  • #2
    New Coder
    Join Date
    Aug 2002
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you don't get any prewritten scripts, do a search in the archive for checking to see if an image is loaded. Once you have that portion you can simply do a window.location.href="newlocation"

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    USA
    Posts
    151
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    function loadImg(src){
        var i=loadImg.a.length;
        loadImg.a[i] = new Image();
        loadImg.a[i].src = src;
    }
    loadImg.a = new Array();
    
    loadImg('img1.gif');
    loadImg('img2.gif');
    loadImg('img3.gif');
    // Repeat as often as necessary
    
    window.onload = function(){
        // This code will execute once all images have loaded.
    }

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    <script language="JavaScript">
    <!--
    var YourImages = new Array("pic1.jpg","pic2.jpg","pic3.jpg","pic4.jpg")// list images to preload

    var preloadYourImages=new Array()

    for (i=0;i<=YourImages.length-1;i++) {
    preloadYourImages[i]=new Image()
    preloadYourImages[i].src=YourImages[i]
    }

    window.onload = function (){
    location="yourpage.htm"
    }
    // -->
    </script>

  • #5
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've used this script before in that fashion on this site

    Never had any problems
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm, never ran into that one, it's pretty nice!
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #7
    New to the CF scene
    Join Date
    Jan 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks folks, much appreciated


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •