Browsers, E-mail, & Web Apps forum

General discussion

javascript function 'setTimeout' problems in FireFox

by ashsechler / September 17, 2009 4:47 AM PDT

there are a couple of projects of mine that don't work with firefox, I think it has something to do with the refresh function 'setTimeout'. have any idea?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Ash Sechler</title>

</head>

<body onload="start();">

<script language="javascript" type="text/javascript">

var content = '<a href="about.html">about/contact</a><br /><a href="links.html">links</a><br/><a href="work.html">artwork</a><br/><a href="freelance.html">freelance</a>';


var shadow='about/contact<br />links<br/>artwork<br/>freelance';


var y = 6;
var x = 7;
var id = 0;
var array = new Array(x);
var array2 = new Array(y);
var begR = Math.floor(Math.random()*256);
var begG = Math.floor(Math.random()*256);
var begB = Math.floor(Math.random()*256);
var endR = Math.floor(Math.random()*256);
var endG = Math.floor(Math.random()*256);
var endB = Math.floor(Math.random()*256);
var boxWidth = 0;
var fontSize = 360;
var dropTop = Math.floor(Math.random()*150)+50;
var dropLeft = Math.floor(Math.random()*400)+50;
var textTop = 83;
var textLeft = 83;
var count=0;

for(var j=0; j<x;j++)
{
array[j] = new Column();
}
for(var i=0; i<y;i++)
{
array2 = new Row();
}


function start(){
document.write('<div style="z-index:-1;"><table cellspacing="0" width="100%" height="100%">');
for(var i=0; i<y;i++)
{
document.write('<tr>');
for(var j=0; j<x;j++)
{
document.write('<td id="'+id+'"></td>');


document.getElementById(id).style.backgroundColor = hex(((array[j].r1+(array[j].rShift*i)) + (array2.r1+(array2.rShift*j)))/2, ((array[j].g1+(array[j].gShift*i)) + (array2.g1+(array2.gShift*j)))/2, ((array[j].b1+(array[j].bShift*i)) + (array2.b1+(array2.bShift*j)))/2);
id++;
}
document.write('</tr>');
}
id=0;
document.write('</table></div>');



document.write('<div class="box" style="position:absolute;top:40px;left:40px;height:400px;background-color:#FFFFFF;z-index:1;"></div><div class="box" id="boxShadow"style="position:absolute;width:600px;height:400px;background-color:#000000;z-index:0;"></div>');


document.write('<div class="text" style="position:absolute;z-index:3;top:80px;left:80px;font-size:70px;">'+content+'</div>');
document.write('<div class="shadow" id="textShadow" style="position:absolute;z-index:2;font-size:70px;">'+shadow+'</div>');

moveShadow();
expandBox();

var aTags = document.getElementsByTagName('a');
for(var i=0;i<aTags.length;i++){
aTags.style.textDecoration="none";
aTags.style.color="#000000";
}
document.getElementsByClassName('shadow')[0].style.color = hex(Math.floor((Math.random()*110)+140), Math.floor((Math.random()*110)+140), Math.floor((Math.random()*110)+140));
}


function hex(r,g,b){
var colorStr="";
var val=new Array(6);
val[0] = Math.floor(r/16);
val[1] = Math.floor(r%16);
val[2] = Math.floor(g/16);
val[3] = Math.floor(g%16);
val[4] = Math.floor(b/16);
val[5] = Math.floor(b%16);
for(var i=0;i<val.length;i++){
val=convert(val);
colorStr+=val;
}
colorStr = '#'+colorStr;
return colorStr;
}

function convert(num){
if(num>15){num=15}
if(num<0){num=0}
switch(num)
{
case 10:
val='A';
break;
case 11:
val='B';
break;
case 12:
val='C';
break;
case 13:
val='D';
break;
case 14:
val='E';
break;
case 15:
val='F';
break;
default:
val=num;
break;
}
return val;
}
function Column(){
this.r1 = begR;
this.g1 = begG;
this.b1 = begB;
this.rShift = Math.floor((endR-begR)/(y-1));
this.gShift = Math.floor((endG-begG)/(y-1));
this.bShift = Math.floor((endB-begB)/(y-1));
}
function Row(){
this.r1 = begR;
this.g1 = begG;
this.b1 = begB;
this.rShift = Math.floor((endR-begR)/(x-1));
this.gShift = Math.floor((endG-begG)/(x-1));
this.bShift = Math.floor((endB-begB)/(x-1));
}
function expandBox() {
boxWidth += 20;
document.getElementsByClassName('box')[0].style.width = boxWidth + 'px';
document.getElementsByClassName('box')[1].style.width = boxWidth + 'px';
if(boxWidth < 600) {

window.setTimeout("expandBox()", 42);
}
}
function textSize() {
fontSize -= 10;
document.getElementsByClassName('text')[0].style.fontSize = fontSize + 'px';
document.getElementsByClassName('shadow')[0].style.fontSize = fontSize + 'px';
if(fontSize > 70) {

window.setTimeout("textSize()", 43);
}
}
function moveShadow(){
count++;
if(count>200){count=1}
dropTop += Math.cos(count*(Math.PI/100))/10;
dropLeft += Math.sin(count*(Math.PI/100))/10;
textTop += Math.cos(count*(Math.PI/100))/20;
textLeft += Math.sin(count*(Math.PI/100))/20;
document.getElementById('boxShadow').style.top = dropTop;
document.getElementById('boxShadow').style.left = dropLeft;
document.getElementById('textShadow').style.top = textTop;
document.getElementById('textShadow').style.left = textLeft;
setTimeout("moveShadow()", 10);
}
</script>
</body>
</html>

Discussion is locked
You are posting a reply to: javascript function 'setTimeout' problems in FireFox
The posting of advertisements, profanity, or personal attacks is prohibited. Please refer to our CNET Forums policies for details. All submitted content is subject to our Terms of Use.
Track this discussion and email me when there are updates

If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.

You are reporting the following post: javascript function 'setTimeout' problems in FireFox
This post has been flagged and will be reviewed by our staff. Thank you for helping us maintain CNET's great community.
Sorry, there was a problem flagging this post. Please try again now or at a later time.
If you believe this post is offensive or violates the CNET Forums' Usage policies, you can report it below (this will not automatically remove the post). Once reported, our moderators will be notified and the post will be reviewed.
Collapse -
Your best bet,
by MarkFlax Forum moderator / September 17, 2009 5:54 AM PDT

is to repost this in one of CNET's Web forums, eg;
Coding and scripting. or
Web design and hosting.

The experts hang out there, so good luck.

I'm no expert, (in any way), but I always thought that the setting up of Javascript had to come before the <body> element. Then the script was called from within the body element. Just a thought.

Mark

Collapse -
Re: javascript
by Kees Bakker / September 17, 2009 6:08 AM PDT
In reply to: Your best bet,

A script definition can be anywhere, both in the body and in the header. Doesn't make a difference I know of. But I'm not an expert either.

Calling a script is done in the body, indeed.

Kees

Collapse -
What is known.
by R. Proffitt Forum moderator / September 17, 2009 10:24 PM PDT
In reply to: Re: javascript

This issue is under discussion but the OP may not want to know that or see those discussions. They may want it solved. They may not want to get it on the bug list but again they may be only interested in a solution.

Good thing the source code is open source?
Bob

Popular Forums
icon
Computer Newbies 10,686 discussions
icon
Computer Help 54,365 discussions
icon
Laptops 21,181 discussions
icon
Networking & Wireless 16,313 discussions
icon
Phones 17,137 discussions
icon
Security 31,287 discussions
icon
TVs & Home Theaters 22,101 discussions
icon
Windows 7 8,164 discussions
icon
Windows 10 2,657 discussions

The Samsung RF23M8090SG

One of the best French door fridges we've tested

A good-looking fridge with useful features like an auto-filling water pitcher and a temperature-adjustable "FlexZone" drawer. It was a near-flawless performer in our cooling tests.