Results 1 to 1 of 1

Thread: random image onload

  1. #1
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    798
    Thanks
    86
    Thanked 2 Times in 2 Posts

    Default random image onload

    Hey all,

    I am looking for a script that loads a different image every time the page gets loaded.
    I found this script by Twey on this forum:
    Code:
    <script type="text/javascript">
    window.onload = function() {
    var randomImages = [
    "folder1/image1.png",
    "folder2/image2.jpg",
    "folder2/image3.gif",
    "folder3/image4.tga"
    ];
    document.images['random_image'].src = randomImages[Math.floor(Math.random() * randomImages.length)];
    };
    </script>
    </head>
    <body>
    <img id="random_image" src="defaultImage.png">I had to answer this purely because it's 0547, my vision's getting a little blurry, and I read the "random" in the title as "condom."
    Couldn't help leaving what you wrote Twey, but anyway.

    Tricky thing is the following, which can be seen here: http://www.portretkunst.be
    1/ I would like to have the three images be randomly replaced by others onload
    2/ there is already a JavaScript code in the head (for the multiple select boxes), maybe therefore Twey's code doesn't work here:
    Code:
    <script type="text/javascript">
    (function(){
    	function loader(){
    		initListGroup('chainedmenu', document.listmenu0.firstlevel, document.listmenu0.secondlevel, document.listmenu0.thirdlevel, 'savestate');
    	}
    	if (window.addEventListener)
    		window.addEventListener('load', loader, false);
    	else if (window.attachEvent)
    		window.attachEvent('onload', loader);
    })();
    </script>
    I would also like to have every image linked to a page within the same site. Any suggestions, please ?
    Last edited by chechu; 11-28-2009 at 11:41 AM.

Bookmarks

Posting Permissions

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