Results 1 to 1 of 1

Thread: random image onload

  1. #1
    Join Date
    Jul 2006
    Antwerp, Belgium (Europe)
    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:
    <script type="text/javascript">
    window.onload = function() {
    var randomImages = [
    document.images['random_image'].src = randomImages[Math.floor(Math.random() * randomImages.length)];
    <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:
    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:
    <script type="text/javascript">
    	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);
    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 12:41 PM.


Posting Permissions

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