Click to See Complete Forum and Search --> : Random Image Code Help Please


scottdp
09-28-2009, 12:16 PM
The following code posted below is exactly what I want but for whatever reason I can't get it to work in Firefox or Internet Explorer. It works in Safari though. I have 13 + images that are website sponsors for my website and I want them to randomly change every 3 seconds. When you click on a new page the same thing should happen. As I said, this code works perfectly in Safari but not IE or Firefox. Any idea how that can be overcome?

Thanks!


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>

<base href="http://miccs.squarespace.com/storage/">

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="language" content="english">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">

<title></title>

<script type="text/javascript">

var temp;
var time=3000;
var pics=[
'logo_ermco.gif','Delta2copy.gif','AceAir2.1.gif','Wilhelm2.gif',
'Santarossa2.gif','Trinity2.gif','Ryan2.gif','RMS2.gif',
'Premier2.gif','Pepper2.gif','PCG2.gif','Milestone2.gif',
'Laceindy2.gif','Frakes2.gif','logo_ermco.gif','MJS.gif'
];

function init() {

num=Math.floor(Math.random()*pics.length);
temp=num;

el=document.createElement('img');
el.setAttribute('src',pics[num]);
el.setAttribute('id','myimg');

document.getElementById('img_holder').appendChild(el);

setTimeout(function(){rotateImage(temp)},time);
}

function rotateImage(temp){

num=Math.floor(Math.random()*pics.length);
if(num==temp) {
rotateImage(temp);
}
else {
temp=num;
document.getElementById('myimg').src=pics[num];
setTimeout(function(){rotateImage(temp)},time);
}
}

if(window.addEventListener){
window.addEventListener('load',init,false);
}
else {
if(window.attachEvent){
window.attachEvent('onload',init);
}
}
</script>

</head>
<body>

<div id="img_holder"></div>

</body>
</html>

TheBearMay
09-28-2009, 12:36 PM
Works fine with IE8 and FF 3.5.3

scottdp
09-28-2009, 12:38 PM
That is great but odd at the same time! Why would it not work on the computers I am viewing it on? I am using this code in squarespace.com. The website is not live yet but can be accessed at www.miccs.squarespace.com. Could it be squarespace that is not allowing my code to work on IE and FF?

TheBearMay
09-28-2009, 03:54 PM
Only error I'm showing over there is:

Error: The stylesheet http://miccs.squarespace.com/ was not loaded because its MIME type, "text/html", is not "text/css".
Source File: http://miccs.squarespace.com/
Line: 0

opifex
09-28-2009, 04:33 PM
Look at line 1033.... and below. 2 pages in one doc again. I think your host's page design program is messing with you. If you can't disable that function I would find a new host.