Click to See Complete Forum and Search --> : IE 6 doesn't like my code


David Harrison
06-22-2003, 08:39 AM
What is wrong with this code below:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>

<head>

<meta http-equiv="content-type" content="text/html; charset=windows-1252" />

<title>From The Stem Of The Broccoli</title>

<link rel="stylesheet" type="text/css" href="taylor.css" />

</head>

<body>

<p>
<a href="http://jigsaw.w3.org/css-validator/"><img src="vcss.png" alt="Valid CSS!" class="vcsst" /></a>
<a href="http://validator.w3.org/check/referer"><img src="valid-xhtml11.png" alt="Valid XHTML 1.1!" class="vxhtmlt" /></a>
</p>

<script type="text/javascript"><!--

colours=new Array;
colours[0]="F3AFD4";
colours[1]="FF05B6";
colours[2]="FC05FF";
colours[3]="FF057B";
colours[4]="F77BCA";
colours[5]="DD09AE";

document.bgColor="#"+colours[Math.round(Math.random()*5)];

if(Math.random()>0.9){text="The best thing since sliced Turnips.<br /><a href='index.html'>Back to the beginning.</a>";h=21;w=260;}
else{text="<a href='taylor.html'>I am a link, press my buttons.</a>";h=39;w=306;}

l=document.body.clientWidth;t=document.body.clientHeight;

document.write('<div style="top:'+(Math.round(Math.random()*(t-h))-4)+'px;left:'+(Math.round(Math.random()*(l-w))+1)+'px;">'+text+'</div>');

//--></script>

</body>

</html>

it works in IE 5.x NS 7 and Opera 7 but not IE 6, which is a shame because the only browser it actually NEED'S to work on is IE 6.

David Harrison
06-22-2003, 08:51 AM
I think that in the part of the script that detects the screen height, IE 6 detects it as 0.

CrazyGaz
06-22-2003, 09:01 AM
this will work.

<SCRIPT LANGUAGE="javascript">

var dt = new Date();
var sec = dt.getSeconds();

if (sec==0||sec==6||sec==12||sec==18||sec==24||sec==30||sec==36||sec==42||sec==48||sec==54)
{bgcol="#F3AFD4";
}



if (sec==1||sec==7||sec==13||sec==19||sec==25||sec==31||sec==37||sec==43||sec==49||sec==55)
{bgcol="#FF05B6";
}


if (sec==2||sec==8||sec==14||sec==20||sec==26||sec==32||sec==38||sec==44||sec==50||sec==56)
{bgcol="#FC05FF";
}

if (sec==3||sec==9||sec==15||sec==21||sec==27||sec==33||sec==39||sec==45||sec==51||sec==57)
{bgcol="#FF057B";
}

if (sec==4||sec==10||sec==16||sec==22||sec==28||sec==34||sec==40||sec==46||sec==52||sec==58)
{bgcol="#F88BCA";
}

if (sec==5||sec==11||sec==17||sec==23||sec==29||sec==35||sec==41||sec==47||sec==53||sec==59)
{bgcol="#DD09AE";
}

document.write("<body bgcolor="+ bgcol+">")

</SCRIPT>


A long winded way to do it but I think it should work.

David Harrison
06-22-2003, 09:12 AM
Umm. Thanks but it's not the background colour that's the problem, it's the detecting the screen height bit:

t=document.body.clientHeight;

David Harrison
06-22-2003, 09:13 AM
Yeah, that's the bit Dave.
I know that you've got XP pro, so won't that have IE 6 with it.

(By the way if you wanna check out the site (I did not come up with the content) it's at http://www.geocities.com/caulolli )

AdamBrill
06-22-2003, 09:16 AM
Try using these two lines instead:

l=screen.availWidth;
t=screen.availHeight;

I think it should work then. ;)

David Harrison
06-22-2003, 09:21 AM
That works fine now, thanks.

AdamBrill
06-22-2003, 09:30 AM
No Problem. :)

David Harrison
06-22-2003, 09:30 AM
Oh wait, no it doesn't. That detects the complete height of the browser window, I need just the internal width of the window.

David Harrison
06-22-2003, 09:46 AM
The entire contents of the file taylor.js is this:

colours=new Array;
colours[0]="F3AFD4";
colours[1]="FF05B6";
colours[2]="FC05FF";
colours[3]="FF057B";
colours[4]="F77BCA";
colours[5]="DD09AE";

document.bgColor="#"+colours[Math.round(Math.random()*5)];

David Harrison
06-22-2003, 09:48 AM
Oh, I hadn't spotted that, gimme a sec and I'll fix it.

Edit: Fixed

SlankenOgen
06-22-2003, 10:00 AM
if(sec==0||sec==6||sec==12||sec==18||sec==24||sec==3
0||sec==36||sec==42||sec==48||sec==54)
{bgcol="#F3AFD4";
}



if (sec==1||sec==7||sec==13||sec==19||sec==25||sec==3
1||sec==37||sec==43||sec==49||sec==55)
{bgcol="#FF05B6";
}


if (sec==2||sec==8||sec==14||sec==20||sec==26||sec==3
2||sec==38||sec==44||sec==50||sec==56)
{bgcol="#FC05FF";
} .....etc.


can be simplified with

if(sec%6 == 0) bgcol = "#......"
if(sec%6 == 1) bgcol = "#......"
if(sec%6 == 2) bgcol = "#......"
if(sec%6 == 3) bgcol = "#......"
if(sec%6 == 4) bgcol = "#......"
if(sec%6 == 5) bgcol = "#......"

~mgb

David Harrison
06-22-2003, 10:02 AM
Yeah I changed the .js file and uploaded it again.

I selected the file and pressed edit, and this is copied and pasted straight out of the edit textarea:

colours=new Array();
colours[0]="F3AFD4";
colours[1]="FF05B6";
colours[2]="FC05FF";
colours[3]="FF057B";
colours[4]="F77BCA";
colours[5]="DD09AE";

document.bgColor="#"+colours[Math.round(Math.random()*5)];

David Harrison
06-22-2003, 02:21 PM
Here's a screenshot, you can just see the bottom half of the link at the top of the page.

David Harrison
06-22-2003, 02:37 PM
No I'm talking about the second page:
http://www.geocities.com/caulolli/taylor.html

David Harrison
06-22-2003, 02:41 PM
Sorry, I just assumed that you knew when I posted the code for the page.:D

David Harrison
06-22-2003, 02:48 PM
I just posted the default web-address, I didn't realise that it would throw you off.

David Harrison
06-22-2003, 03:00 PM
It's supposed to:

Detect the internal screen height, subtract the height of some text that will go into a div tag. Then times that by a random number and round the answer. Then take away 4 from that answer (because of the 4px border browsers put above text for some reason) and then with the answer create and position a div tag with some content in it.

It also does a similar thing with the width but that works fine for some reaon.

David Harrison
06-23-2003, 07:20 AM
So what's the difference between what I wrote:
(Math.round(Math.random() * (document.body.clientHeight - h)) - 4)

and what you wrote:
(Math.round(Math.random() * (document.body.clientHeight - h)) - 4)

?

David Harrison
06-23-2003, 02:00 PM
Well I don't understand then where the -ve number is coming from because:

If the inner height is, say, 600 px
And the value of h is 100 px

innerheight - h = 500

then if the random number is 0.2 then
random number * 500 = 100px
when rounded becomes 100px

then subtract 4:
100 - 4 = 96

which is +ve so I don't understand where the -ve bit comes in.

David Harrison
06-24-2003, 04:02 PM
I broke it down as you suggested and the source is attached as a .txt, I found the problem, for some reason it's detecting the internal height as 76px instead of 601px. I have no idea why, if you think that you know then please, by all means, let me know.

David Harrison
06-24-2003, 04:12 PM
I found out why, it's only detecting the height of all the content on the page, as if the page only goes down to there.
How can I fix this, maybe make something have a height of 100% but you're not really supposed to do that.

David Harrison
06-25-2003, 02:55 PM
No, it doesn't work, it does the same as the other one.