Javascript doesn't work in newer Mozillas...

C

Cat

Greetings,

I have an old javascript effect that was running on some of my
sites for quite long, working fine in Netscape (up to 4.75) and
IE. It still works in the newer IEs, but not in the new Mozillas,
neither Firebird nor Firefox (and not in Netscape 7.something).

What is wrong with it? I'm no javascript expert, I just got it
from the net years ago, I don't even know where from. There is
no source url given in it to look up. I've added the code below.

I have exactly the same situation with two other scripts - they
worked for years and suddenly they seem to be 'expired' for Mozilla.
I think it's the same problem with all, so I hope if someone gives
me a helping hand with this one I might fiddle out the other two
as well.

Sorry for the long babble, and thanks to anyone who has the patience
to look over it,

Cat



<BODY BGCOLOR="#000000" ONLOAD="fly()">

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
SmallStars = 27;
LargeStars = 3;
SmallYpos = new Array();
SmallXpos = new Array();
LargeYpos = new Array();
LargeXpos = new Array();
Smallspeed= new Array();
Largespeed= new Array();
ns=(document.layers)?1:0;
if (ns) {
for (i = 0; i < SmallStars; i++) {
document.write("<LAYER NAME='sn"+i+"' LEFT=0 TOP=0 BGCOLOR='#EEDBDB'
CLIP='0,0,1,1'></LAYER>");
}
for (i = 0; i < LargeStars; i++) {
document.write("<LAYER NAME='ln"+i+"' LEFT=0 TOP=0 BGCOLOR='#FFFFF0'
CLIP='0,0,2,2'></LAYER>");
}
}
else {
document.write('<div style="position:absolute;top:0px;left:0px">');
document.write('<div style="position:relative">');
for (i = 0; i < SmallStars; i++) {
document.write('<div id="si"
style="position:absolute;top:0;left:0;width:1px;height:1px;background:#fffff0;font-size:1px"></div>');
}
document.write('</div>');
document.write('</div>');
document.write('<div style="position:absolute;top:0px;left:0px">');
document.write('<div style="position:relative">');
for (i = 0; i < LargeStars; i++) {
document.write('<div id="li"
style="position:absolute;top:0;left:0;width:2px;height:2px;background:#ffffff;font-size:2px"></div>');
}
document.write('</div>');
document.write('</div>');
}
WinHeight =
(document.layers)?window.innerHeight:window.document.body.clientHeight;
WinWidth =
(document.layers)?window.innerWidth:window.document.body.clientWidth;
for (i = 0; i < SmallStars; i++) {
SmallYpos = Math.round(Math.random() * WinHeight);
SmallXpos = Math.round(Math.random() * WinWidth);
Smallspeed= Math.random() * 5 + 1;
}
for (i = 0; i < LargeStars; i++) {
LargeYpos = Math.round(Math.random() * WinHeight);
LargeXpos = Math.round(Math.random() * WinWidth);
Largespeed = Math.random() * 10 + 5;
}
function fly() {
var WinHeight =
(document.layers)?window.innerHeight:window.document.body.clientHeight;
var WinWidth =
(document.layers)?window.innerWidth:window.document.body.clientWidth;
var hscrll =
(document.layers)?window.pageYOffset:document.body.scrollTop;
var wscrll =
(document.layers)?window.pageXOffset:document.body.scrollLeft;
for (i = 0; i < LargeStars; i++) {
LargeXpos -= Largespeed;
if (LargeXpos < -10) {
LargeXpos = WinWidth;
LargeYpos = Math.round(Math.random() * WinHeight);
Largespeed = Math.random() * 10 + 5;
}
if (ns) {
document.layers['ln'+i].left = LargeXpos;
document.layers['ln'+i].top = LargeYpos + hscrll;
}
else {
li.style.pixelLeft = LargeXpos;
li.style.pixelTop = LargeYpos + hscrll;
}
}
for (i = 0; i < SmallStars; i++) {
SmallXpos -= Smallspeed;
if (SmallXpos < -10) {
SmallXpos = WinWidth;
SmallYpos = Math.round(Math.random()*WinHeight);
Smallspeed = Math.random() * 5 + 1;
}
if (ns) {
document.layers['sn'+i].left = SmallXpos;
document.layers['sn'+i].top = SmallYpos+hscrll;
}
else {
si.style.pixelLeft = SmallXpos;
si.style.pixelTop = SmallYpos+hscrll;
}
}
setTimeout('fly()', 10);
}
// End -->


</SCRIPT>
 
R

Richard

Greetings,
I have an old javascript effect that was running on some of my
sites for quite long, working fine in Netscape (up to 4.75) and
IE. It still works in the newer IEs, but not in the new Mozillas,
neither Firebird nor Firefox (and not in Netscape 7.something).

Maybe due to the ancient ways of doing things.

document.write('</div>');
document.write('</div>');
document.write('<div style="position:absolute;top:0px;left:0px">');
document.write('<div style="position:relative">');


Convert all of this stuff into css.
<div> should come before </div> not as you show it.

in css it would look like
div.sample { position:absolute; top:0px; left;0px; }

<div class="sample">text</div>

You might want to brush up on existing acceptable JS conventions.
Then tweak your script accordingly.
 
R

Robert

Greetings,

I have an old javascript effect that was running on some of my
sites for quite long, working fine in Netscape (up to 4.75) and
IE. It still works in the newer IEs, but not in the new Mozillas,
neither Firebird nor Firefox (and not in Netscape 7.something).

This script contains the Netscape 4.x layer tag. This tag was dropped
from the Gekco base browsers. Netscape 6.x, firefox, etc. This is the
reason for the failure.

Rbert
 
S

Spats30

Couple of things: almost no-one is supporting NS 4.x vesions anymore.
It's usage is nominal, anymore, so remove it.

Then what is happening in your script is that the logic checks for old
NS versions (document.layers), if found, then use these specific old NS
properties, else assume IE and use proprietary IE properties. Newer NS
and Firefox browsers follow the ECMA standards better and don't support
either set of proprietary properties used in your script.

What you should do is search for a whole new script, or go through
manually, and replace anything with document.layers with new code
supported by NS 6+. It would take a long time to be more specific for
this post, but followup on your own and you'll learn a lot along the
way.


Greetings,

I have an old javascript effect that was running on some of my
sites for quite long, working fine in Netscape (up to 4.75) and
IE. It still works in the newer IEs, but not in the new Mozillas,
neither Firebird nor Firefox (and not in Netscape 7.something).

What is wrong with it? I'm no javascript expert, I just got it
from the net years ago, I don't even know where from. There is
no source url given in it to look up. I've added the code below.

I have exactly the same situation with two other scripts - they
worked for years and suddenly they seem to be 'expired' for Mozilla.
I think it's the same problem with all, so I hope if someone gives
me a helping hand with this one I might fiddle out the other two
as well.

Sorry for the long babble, and thanks to anyone who has the patience
to look over it,

Cat



<BODY BGCOLOR="#000000" ONLOAD="fly()">

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
SmallStars = 27;
LargeStars = 3;
SmallYpos = new Array();
SmallXpos = new Array();
LargeYpos = new Array();
LargeXpos = new Array();
Smallspeed= new Array();
Largespeed= new Array();
ns=(document.layers)?1:0;
if (ns) {
for (i = 0; i < SmallStars; i++) {
document.write("<LAYER NAME='sn"+i+"' LEFT=0 TOP=0 BGCOLOR='#EEDBDB'
CLIP='0,0,1,1'></LAYER>");
}
for (i = 0; i < LargeStars; i++) {
document.write("<LAYER NAME='ln"+i+"' LEFT=0 TOP=0 BGCOLOR='#FFFFF0'
CLIP='0,0,2,2'></LAYER>");
}
}
else {
document.write('<div style="position:absolute;top:0px;left:0px">');
document.write('<div style="position:relative">');
for (i = 0; i < SmallStars; i++) {
document.write('<div id="si"
style="position:absolute;top:0;left:0;width:1px;height:1px;background:#fffff0;font-size:1px"> said:
}
document.write('</div>');
document.write('</div>');
document.write('<div style="position:absolute;top:0px;left:0px">');
document.write('<div style="position:relative">');
for (i = 0; i < LargeStars; i++) {
document.write('<div id="li"
style="position:absolute;top:0;left:0;width:2px;height:2px;background:#ffffff;font-size:2px"> said:
}
document.write('</div>');
document.write('</div>');
}
WinHeight =
(document.layers)?window.innerHeight:window.document.body.clientHeight;
WinWidth =
(document.layers)?window.innerWidth:window.document.body.clientWidth;
for (i = 0; i < SmallStars; i++) {
SmallYpos = Math.round(Math.random() * WinHeight);
SmallXpos = Math.round(Math.random() * WinWidth);
Smallspeed= Math.random() * 5 + 1;
}
for (i = 0; i < LargeStars; i++) {
LargeYpos = Math.round(Math.random() * WinHeight);
LargeXpos = Math.round(Math.random() * WinWidth);
Largespeed = Math.random() * 10 + 5;
}
function fly() {
var WinHeight =
(document.layers)?window.innerHeight:window.document.body.clientHeight;
var WinWidth =
(document.layers)?window.innerWidth:window.document.body.clientWidth;
var hscrll =
(document.layers)?window.pageYOffset:document.body.scrollTop;
var wscrll =
(document.layers)?window.pageXOffset:document.body.scrollLeft;
for (i = 0; i < LargeStars; i++) {
LargeXpos -= Largespeed;
if (LargeXpos < -10) {
LargeXpos = WinWidth;
LargeYpos = Math.round(Math.random() * WinHeight);
Largespeed = Math.random() * 10 + 5;
}
if (ns) {
document.layers['ln'+i].left = LargeXpos;
document.layers['ln'+i].top = LargeYpos + hscrll;
}
else {
li.style.pixelLeft = LargeXpos;
li.style.pixelTop = LargeYpos + hscrll;
}
}
for (i = 0; i < SmallStars; i++) {
SmallXpos -= Smallspeed;
if (SmallXpos < -10) {
SmallXpos = WinWidth;
SmallYpos = Math.round(Math.random()*WinHeight);
Smallspeed = Math.random() * 5 + 1;
}
if (ns) {
document.layers['sn'+i].left = SmallXpos;
document.layers['sn'+i].top = SmallYpos+hscrll;
}
else {
si.style.pixelLeft = SmallXpos;
si.style.pixelTop = SmallYpos+hscrll;
}
}
setTimeout('fly()', 10);
}
// End -->


</SCRIPT>
 
L

Lee

Robert said:
This script contains the Netscape 4.x layer tag. This tag was dropped
from the Gekco base browsers. Netscape 6.x, firefox, etc. This is the
reason for the failure.

Since there is no document.layers object, it doesn't detect modern
Netscape as being Netscape at all, and so it never writes the LAYER
tags. It writes the IE code, instead.

However, even the IE code is garbage. It creates multiple <div>
tags with the same ID and then refers to them as elements of a
global array by the name of that ID tag.

It's pretty sad that IE tolerates this garbage.

You would be better off find new code. This sort of thing should be
available.
 
R

RobB

Lee said:
Robert said:

Since there is no document.layers object, it doesn't detect modern
Netscape as being Netscape at all, and so it never writes the LAYER
tags. It writes the IE code, instead.

However, even the IE code is garbage. It creates multiple <div>
tags with the same ID and then refers to them as elements of a
global array by the name of that ID tag.

It's pretty sad that IE tolerates this garbage.

You would be better off find new code. This sort of thing should be
available.

Lee pretty much covered it ('garbage')...in addition, the script is
written in such a way as to optimize differences in animation
efficiencies between (some) browsers, making any sort of uniform
timebase a kludge at best. style.pixelLeft/Top are IE-only. In any
event...dumped the LAYERS, cleaned it up a bit. Whatever.

<html>
<head>
<title>untitled</title>
</head>
<body bgcolor="#000000"
onresize="window.location.reload()"
onload="setInterval('fly()', window.createPopup?80:1);"><!-- a little
speed equalization -->
<script type="text/javascript">

var SmallStars = 27;
var LargeStars = 3;
var SmallYpos = [];
var SmallXpos = [];
var LargeYpos = [];
var LargeXpos = [];
var Smallspeed = [];
var Largespeed = [];
document.write(
'<div style="position:absolute;top:0px;left:0px;">',
'<div style="position:relative;">'
);
for (i = 0; i < SmallStars; i++) {
document.write(
'<div id="si' + i + '" ',
'style="position:absolute;top:0;left:0;',
'width:1px;height:1px;background:#fff;',
'font-size:1px;"></div>'
);
}
document.write(
'</div>','</div>',
'<div style="position:absolute;top:0;left:0;">',
'<div style="position:relative;">'
);
for (i = 0; i < LargeStars; i++) {
document.write(
'<div id="li' + i + '" ',
'style="position:absolute;top:0;left:0;',
'width:2px;height:2px;background:#fff;',
'font-size:2px;"></div>'
);
}
document.write('</div>','</div>');
WinHeight = ('undefined' != typeof window.innerHeight)?
window.innerHeight : document.body.clientHeight;
WinWidth = ('undefined' != typeof window.innerWidth)?
window.innerWidth-5 : document.body.clientWidth-5;
for (i = 0; i < SmallStars; i++) {
SmallYpos = Math.round(Math.random() * WinHeight);
SmallXpos = Math.round(Math.random() * WinWidth);
Smallspeed= Math.random() * 5 + 1;
}
for (i = 0; i < LargeStars; i++) {
LargeYpos = Math.round(Math.random() * WinHeight);
LargeXpos = Math.round(Math.random() * WinWidth);
Largespeed = Math.random() * 10 + 5;
}

function fly() {
var hscrll = ('undefined' != typeof window.pageYOffset)?
window.pageYOffset : document.body.scrollTop;
var wscrll = ('undefined' != typeof window.pageXOffset)?
window.pageXOffset : document.body.scrollLeft;
for (i = 0; i < LargeStars; i++) {
LargeXpos -= Largespeed;
if (LargeXpos < -10) {
LargeXpos = WinWidth;
LargeYpos = Math.round(Math.random() * WinHeight);
Largespeed = Math.random() * 10 + 5;
}
}
i = 0;
while (li = document.getElementById('li' + i)) {
li.style.left = LargeXpos + 'px';
li.style.top = LargeYpos[i++] + hscrll + 'px';
}
for (i = 0; i < SmallStars; i++) {
SmallXpos -= Smallspeed;
if (SmallXpos < -10) {
SmallXpos = WinWidth;
SmallYpos = Math.round(Math.random()*WinHeight);
Smallspeed = Math.random() * 5 + 1;
}
}
i = 0;
while (si = document.getElementById('si' + i)) {
si.style.left = SmallXpos + 'px';
si.style.top = SmallYpos[i++] + hscrll + 'px';
}
}

</script>
</body>
</html>
 
R

Randy Webb

Richard said:
Maybe due to the ancient ways of doing things.

document.write('</div>');
document.write('</div>');
document.write('<div style="position:absolute;top:0px;left:0px">');
document.write('<div style="position:relative">');


Convert all of this stuff into css.
<div> should come before </div> not as you show it.

To the OP: Ignore the above advice. If Richard had bothered to *read*
the code, he would have noticed that it does indeed have them in the
correct order. It's typical of his hairbrained replies.
 
R

RobB

(snip)

OK, cleaned this up a bit. Beware of lunatic line breaking courtesy of
googlegroups (turn on error reporting and look for unterminated
strings).

<html>
<head>
<title>untitled</title>
</head>
<body style="background:#000;"
onresize="window.location.reload()"
onload="if(document.getElementById)setInterval('fly()', 40)">
<script type="text/javascript">

var SmallStars = 27;
var LargeStars = 3;
var SmallYpos = [];
var SmallXpos = [];
var LargeYpos = [];
var LargeXpos = [];
var Smallspeed = [];
var Largespeed = [];
document.write(
'<div style="position:absolute;top:0px;left:0px;">',
'<div style="position:relative;">'
);
for (i = 0; i < SmallStars; i++) {
document.write(
'<div id="si' + i + '" ',
'style="position:absolute;top:0;left:0;',
'width:1px;height:1px;background:#fff;',
'font-size:1px;"></div>'
);
}
document.write(
'</div>','</div>',
'<div style="position:absolute;top:0;left:0;">',
'<div style="position:relative;">'
);
for (i = 0; i < LargeStars; i++) {
document.write(
'<div id="li' + i + '" ',
'style="position:absolute;top:0;left:0;',
'width:2px;height:2px;background:#fff;',
'font-size:2px;"></div>'
);
}
document.write('</div>','</div>');
WinHeight = ('undefined' != typeof window.innerHeight)?
window.innerHeight : document.body.clientHeight;
WinWidth = ('undefined' != typeof window.innerWidth)?
window.innerWidth-5 : document.body.clientWidth-5;
for (i = 0; i < SmallStars; i++) {
SmallYpos = Math.round(Math.random() * WinHeight);
SmallXpos = Math.round(Math.random() * WinWidth);
Smallspeed= Math.random() * 5 + 1;
}
for (i = 0; i < LargeStars; i++) {
LargeYpos = Math.round(Math.random() * WinHeight);
LargeXpos = Math.round(Math.random() * WinWidth);
Largespeed = Math.random() * 10 + 5;
}

function fly() {
var hscrll = ('undefined' != typeof window.pageYOffset)?
window.pageYOffset : document.body.scrollTop;
var wscrll = ('undefined' != typeof window.pageXOffset)?
window.pageXOffset : document.body.scrollLeft;
for (i = 0; i < LargeStars; i++) {
LargeXpos -= Largespeed;
if (LargeXpos < -10) {
LargeXpos = WinWidth;
LargeYpos = Math.round(Math.random() * WinHeight);
Largespeed = Math.random() * 10 + 5;
}
}
i = 0;
while (li = document.getElementById('li' + i)) {
li.style.left = LargeXpos + 'px';
li.style.top = LargeYpos[i++] + hscrll + 'px';
}
for (i = 0; i < SmallStars; i++) {
SmallXpos -= Smallspeed;
if (SmallXpos < -10) {
SmallXpos = WinWidth;
SmallYpos = Math.round(Math.random()*WinHeight);
Smallspeed = Math.random() * 5 + 1;
}
}
i = 0;
while (si = document.getElementById('si' + i)) {
si.style.left = SmallXpos + 'px';
si.style.top = SmallYpos[i++] + hscrll + 'px';
}
}

</script>
</body>
</html>
 
C

Cat

Hi,

thank you so very much for this, it works like a charm now.
I read the newsgroups in my old Netscape 4.8 still, so I don't
have problems with the linebreaks.

I will go through it and see where you made changes, hopefully
I learn something from it. For some reason, Javascript, like
cgi, comes terribly hard to me, even though I love to use it.
Maybe because it has something to do with logic, that's just not
my world (I'm a former painter that started out as a designer,
still longing for the brushes..;)

Thanks again,

Cat


(snip)

OK, cleaned this up a bit. Beware of lunatic line breaking courtesy of
googlegroups (turn on error reporting and look for unterminated
strings).

<html>
<head>
<title>untitled</title>
</head>
<body style="background:#000;"
onresize="window.location.reload()"
onload="if(document.getElementById)setInterval('fly()', 40)">
<script type="text/javascript">

var SmallStars = 27;
var LargeStars = 3;
var SmallYpos = [];
var SmallXpos = [];
var LargeYpos = [];
var LargeXpos = [];
var Smallspeed = [];
var Largespeed = [];
document.write(
'<div style="position:absolute;top:0px;left:0px;">',
'<div style="position:relative;">'
);
for (i = 0; i < SmallStars; i++) {
document.write(
'<div id="si' + i + '" ',
'style="position:absolute;top:0;left:0;',
'width:1px;height:1px;background:#fff;',
'font-size:1px;"></div>'
);
}
document.write(
'</div>','</div>',
'<div style="position:absolute;top:0;left:0;">',
'<div style="position:relative;">'
);
for (i = 0; i < LargeStars; i++) {
document.write(
'<div id="li' + i + '" ',
'style="position:absolute;top:0;left:0;',
'width:2px;height:2px;background:#fff;',
'font-size:2px;"></div>'
);
}
document.write('</div>','</div>');
WinHeight = ('undefined' != typeof window.innerHeight)?
window.innerHeight : document.body.clientHeight;
WinWidth = ('undefined' != typeof window.innerWidth)?
window.innerWidth-5 : document.body.clientWidth-5;
for (i = 0; i < SmallStars; i++) {
SmallYpos = Math.round(Math.random() * WinHeight);
SmallXpos = Math.round(Math.random() * WinWidth);
Smallspeed= Math.random() * 5 + 1;
}
for (i = 0; i < LargeStars; i++) {
LargeYpos = Math.round(Math.random() * WinHeight);
LargeXpos = Math.round(Math.random() * WinWidth);
Largespeed = Math.random() * 10 + 5;
}

function fly() {
var hscrll = ('undefined' != typeof window.pageYOffset)?
window.pageYOffset : document.body.scrollTop;
var wscrll = ('undefined' != typeof window.pageXOffset)?
window.pageXOffset : document.body.scrollLeft;
for (i = 0; i < LargeStars; i++) {
LargeXpos -= Largespeed;
if (LargeXpos < -10) {
LargeXpos = WinWidth;
LargeYpos = Math.round(Math.random() * WinHeight);
Largespeed = Math.random() * 10 + 5;
}
}
i = 0;
while (li = document.getElementById('li' + i)) {
li.style.left = LargeXpos + 'px';
li.style.top = LargeYpos[i++] + hscrll + 'px';
}
for (i = 0; i < SmallStars; i++) {
SmallXpos -= Smallspeed;
if (SmallXpos < -10) {
SmallXpos = WinWidth;
SmallYpos = Math.round(Math.random()*WinHeight);
Smallspeed = Math.random() * 5 + 1;
}
}
i = 0;
while (si = document.getElementById('si' + i)) {
si.style.left = SmallXpos + 'px';
si.style.top = SmallYpos[i++] + hscrll + 'px';
}
}

</script>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top