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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy Random Images work well in Mac browsers but fail in IE 8

    Hello all,

    After using and altering a javascript random image generator code from the web, I've got it doing exactly what I wanted...but only on the mac.

    The page is supposed to display 5 random images next to each other.

    Mac Opera shows 3 of 5 images.IE 8 on the PC does the same as Mac Opera, displaying images from gallery[0], gallery[2] and gallery[4].

    Between the gallery[0] and gallery[2] images, the page displays: pickImageFrom(1);
    Between the gallery[2] and gallery[4] images, the page displays: pickImageFrom(3);

    Code:
    var gallery = new Array();
    gallery[0] = new Array("narrow_01.jpg","narrow_02.jpg","narrow_03.jpg","narrow_04.jpg","narrow_05.jpg");
    gallery[1] = new Array("narrow_06.jpg","narrow_07.jpg","narrow_08.jpg","narrow_09.jpg","narrow_10.jpg");
    gallery[2] = new Array("narrow_11.jpg","narrow_12.jpg","narrow_13.jpg","narrow_14.jpg","narrow_15.jpg");
    gallery[3] = new Array("narrow_16.jpg","narrow_17.jpg","narrow_18.jpg","narrow_19.jpg","narrow_20.jpg");
    gallery[4] = new Array("narrow_21.jpg","narrow_22.jpg","narrow_23.jpg","narrow_24.jpg","narrow_25.jpg");
    
    function pickImageFrom(whichGallery)
    {
    var idx = Math.floor(Math.random() * gallery[whichGallery].length);
    document.write('<img src="images/random/' + gallery[whichGallery][idx] + '" class="special" width="180" ');
    }
    My HTML is:
    Code:
    				<script language="javascript" type="text/javascript">
    				pickImageFrom(0);
    				</script>
                    <script language="javascript" type="text/javascript">
                    pickImageFrom(1);
    				</script>
                    <script language="javascript" type="text/javascript">
    				pickImageFrom(2);
    				</script>
                    <script language="javascript" type="text/javascript">
    				pickImageFrom(3);
    				</script>
                    <script language="javascript" type="text/javascript">
    				pickImageFrom(4);
                    </script>
                    <noscript>
                    <img src="opener_03.jpg" alt="" />
    				</noscript>

    The site is listed here:
    http://huntdesign.com/HuntDesignWebs...ent/index.html

    The js is referred from here:
    http://huntdesign.com/HuntDesignWebs...ontent/hunt.js

    Your help would be invaluable since I really don't want to go back to the boss and say we *have* to use a single static image. :-)

    Thanks!

  • #2
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    That one was hard to spot.

    You don't close your <img> tag here:
    Code:
    document.write('<img src="images/random/' + gallery[whichGallery][idx] + '" class="special" width="180" ');

  • Users who have thanked venegal for this post:

    littleSparky (05-05-2009)

  • #3
    New to the CF scene
    Join Date
    May 2009
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Smile Random Image problem solved

    Many thanks to you, venegal.
    That was the missing element.

    Everything works clean and well.

    Do you think I should post the snippet of my code for all or is it something everybody already knows?


  •  

    Tags for this Thread

    Posting Permissions

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