Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

My javascript works in IE, but not NN, and ideas?

Status
Not open for further replies.

jackyl

Programmer
Oct 23, 2001
44
CA
this script changes images on the fly ... every few seconds it loads a new photo, but it doesn't reload images in NN ... any suggestions?

<script language = &quot;Javascript&quot;><!--
function MakeArray(n) {
this.length = n;
for (var i = 1; i <= n; i++) {
this = null;
}
return this;
}
var NumberImages = 16;
var imag = new MakeArray(NumberImages);

imag[1] = &quot;../image/1.jpg&quot;;
imag[2] = &quot;../image/2.jpg&quot;;
imag[3] = &quot;../image/3.jpg&quot;;
imag[4] = &quot;../image/4.jpg&quot;;
imag[5] = &quot;../image/5.jpg&quot;;
imag[6] = &quot;../image/6.jpg&quot;;
imag[7] = &quot;../image/7.jpg&quot;;
imag[8] = &quot;../image/8.jpg&quot;;
imag[9] = &quot;../image/9.jpg&quot;;
imag[10] = &quot;../image/10.jpg&quot;;
imag[11] = &quot;../image/11.jpg&quot;;
imag[12] = &quot;../image/12.jpg&quot;;
imag[13] = &quot;../image/13.jpg&quot;;
imag[14] = &quot;../image/14.jpg&quot;;
imag[15] = &quot;../image/15.jpg&quot;;
imag[16] = &quot;../image/16.jpg&quot;;

// set up the random seed and value
function GetRand()
{
day = new Date();
seed = day.getTime();
return parseInt(((seed - (parseInt(seed/1000,10) * 1000)) /10) /100 * NumberImages + 1,10);
}
var RandNumber = GetRand();
var OldRandNum = RandNumber;
document.write('<img src=&quot;',imag[RandNumber],'&quot; border=0 bordercolor=black id=&quot;img060739&quot; width=&quot;282&quot; height=&quot;151&quot;>');
function NewImage060739()
{
while( OldRandNum == RandNumber) RandNumber = GetRand();
OldRandNum = RandNumber;
document.all.img060739.src = imag[RandNumber];
window.setTimeout(&quot;NewImage060739()&quot;,6000);
}
if(document.all) //if NS ever supports this
window.setTimeout(&quot;NewImage060739()&quot;,6000);
// --></script>
 
Let's clean ALL this up a bit:

var imag = new Array(&quot;1.jpg&quot;,&quot;2.jpg&quot;,&quot;3.jpg&quot;,&quot;4.jpg&quot;,&quot;5.jpg&quot;,&quot;6.jpg&quot;,&quot;7.jpg&quot;,&quot;8.jpg&quot;,&quot;9.jpg&quot;,&quot;10.jpg&quot;,&quot;11.jpg&quot;,&quot;12.jpg&quot;,&quot;13.jpg&quot;,&quot;14.jpg&quot;,&quot;15.jpg&quot;,&quot;16.jpg&quot;);

// set up the random seed and value
function GetRand()
{
day = new Date();
seed = day.getTime();
return parseInt(((seed - (parseInt(seed/1000,10) * 1000)) /10) /100 * imag.length + 1,10);
}

var RandNumber = GetRand();
var OldRandNum = RandNumber;
document.write('<img src=&quot;../image/' + imag[RandNumber] + '&quot; border=0 bordercolor=black name=&quot;img060739&quot; width=&quot;282&quot; height=&quot;151&quot;>');

function NewImage060739()
{
while( OldRandNum == RandNumber) RandNumber = GetRand();
OldRandNum = RandNumber;
document.img060739.src = '../image/' + imag[RandNumber];
}

window.setInterval(&quot;NewImage060739()&quot;,6000);
</script>
 
there r some commands in JavaScript that work differntly with IE and Netscape. most probably this is the reason y u r facing this problem. u need to look out for this
 
trollacious, your script doesn't work in NN 4.7 ...

I have come up with one that does though ... it follows:

<!-- in the head -->
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>

<!-- Begin
var interval = 3.5; // delay between rotating images (in seconds)
var random_display = 1; // 0 = no, 1 = yes
interval *= 1000;

var image_index = 0;
image_list = new Array();
image_list[image_index++] = new imageItem(&quot;../image/1.jpg&quot;);
image_list[image_index++] = new imageItem(&quot;../image/2.jpg&quot;);
image_list[image_index++] = new imageItem(&quot;../image/3.jpg&quot;);
image_list[image_index++] = new imageItem(&quot;../image/4.jpg&quot;);
image_list[image_index++] = new imageItem(&quot;../image/5.jpg&quot;);
image_list[image_index++] = new imageItem(&quot;../image/6.jpg&quot;);
image_list[image_index++] = new imageItem(&quot;../image/7.jpg&quot;);
image_list[image_index++] = new imageItem(&quot;../image/8.jpg&quot;);
image_list[image_index++] = new imageItem(&quot;../image/9.jpg&quot;);
image_list[image_index++] = new imageItem(&quot;../image/10.jpg&quot;);
image_list[image_index++] = new imageItem(&quot;../image/11.jpg&quot;);
image_list[image_index++] = new imageItem(&quot;../image/12.jpg&quot;);
image_list[image_index++] = new imageItem(&quot;../image/13.jpg&quot;);
image_list[image_index++] = new imageItem(&quot;../image/14.jpg&quot;);
image_list[image_index++] = new imageItem(&quot;../image/15.jpg&quot;);
image_list[image_index++] = new imageItem(&quot;../image/16.jpg&quot;);
var number_of_image = image_list.length;
function imageItem(image_location) {
this.image_item = new Image();
this.image_item.src = image_location;
}
function get_ImageItemLocation(imageObj) {
return(imageObj.image_item.src)
}
function generate(x, y) {
var range = y - x + 1;
return Math.floor(Math.random() * range) + x;
}
function getNextImage() {
if (random_display) {
image_index = generate(0, number_of_image-1);
}
else {
image_index = (image_index+1) % number_of_image;
}
var new_image = get_ImageItemLocation(image_list[image_index]);
return(new_image);
}
function rotateImage(place) {
var new_image = getNextImage();
document[place].src = new_image;
var recur_call = &quot;rotateImage('&quot;+place+&quot;')&quot;;
setTimeout(recur_call, interval);
}
// End -->

</script>

<!-- in the body tag -->
OnLoad=&quot;rotateImage('rImage')&quot;

<!-- where you want the image to appear -->
<img name=&quot;rImage&quot; src=&quot;../image/1.jpg&quot; width=282 height=151>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top