Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-05-2009, 06:21 PM   PM User | #1
littleSparky
New to the CF scene

 
Join Date: May 2009
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
littleSparky is an unknown quantity at this point
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!
littleSparky is offline   Reply With Quote
Old 05-05-2009, 07:30 PM   PM User | #2
venegal
Gütkodierer


 
Join Date: Apr 2009
Posts: 2,127
Thanks: 1
Thanked 426 Times in 424 Posts
venegal has a spectacular aura aboutvenegal has a spectacular aura about
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" ');
venegal is offline   Reply With Quote
Users who have thanked venegal for this post:
littleSparky (05-05-2009)
Old 05-05-2009, 07:56 PM   PM User | #3
littleSparky
New to the CF scene

 
Join Date: May 2009
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
littleSparky is an unknown quantity at this point
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?
littleSparky is offline   Reply With Quote
Reply

Bookmarks

Tags
fail, internet explorer, mac, random image

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:08 AM.


Advertisement
Log in to turn off these ads.