473,395 Members | 1,471 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to fix this javascript to work in Netscape 7.1 and 4.x (also for IE4 and IE6)

I understand that document.layers is no longer supported in Netscape
7.1 but I am not sure on how to fix the code so that it will work with
Netscape 7.1.

I understand that document.all is no longer supported in IE6 but I am
not sure on how to fix the code so that it will work with IE6.

<!--
var no = 10; // snow number
var speed = 15; // smaller number moves the snow faster
var snowflake = "snowflake.gif";
var ns4up = is_nav4up;
var ie4up = is_ie4up;
var dx, xp, yp; // coordinate and position variables
var am, stx, sty; // amplitude and step variables
var i, doc_width = 723, doc_height = 480;
if (ns4up)
{
alert("there");
doc_width = self.innerWidth;
doc_height = self.innerHeight;
}
else if (ie4up)
{
alert("here");
doc_width = document.body.clientWidth;
doc_height = document.body.clientHeight;
}
dx = new Array();
xp = new Array();
yp = new Array();
am = new Array();
stx = new Array();
sty = new Array();
for (i = 0; i < no; ++ i)
{
dx[i] = 0; // set coordinate variables
xp[i] = Math.random()*(doc_width-50); // set position variables
yp[i] = Math.random()*doc_height;
am[i] = Math.random()*40; // set amplitude variables
stx[i] = 0.02 + Math.random()/10; // set step variables
sty[i] = 0.7 + Math.random(); // set step variables
if (ns4up)
{ // set layers
if (i == 0)
{
document.write("<layer name=\"dot"+ i +"\" left=\"15\" ");
document.write("top=\"15\" visibility=\"show\"><img src=\"");
document.write(snowflake + "\" border=\"0\"></layer>");
} else
{
document.write("<layer name=\"dot"+ i +"\" left=\"15\" ");
document.write("top=\"15\" visibility=\"show\"><img src=\"");
document.write(snowflake + "\" border=\"0\"></layer>");
}
} else if (ie4up)
{
if (i == 0)
{
document.write("<div id=\"dot"+ i +"\" style=\"POSITION: ");
document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: ");
document.write("visible; TOP: 15px; LEFT: 15px;\"><img src=\"");
document.write(snowflake + "\" border=\"0\"></div>");
} else
{
document.write("<div id=\"dot"+ i +"\" style=\"POSITION: ");
document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: ");
document.write("visible; TOP: 15px; LEFT: 15px;\"><img src=\"");
document.write(snowflake + "\" border=\"0\"></div>");
}
}
}

function snowNS()
{ // Netscape main animation function
for (i = 0; i < no; ++ i)
{ // iterate for every dot
yp[i] += sty[i];
if (yp[i] > doc_height-50)
{
xp[i] = Math.random()*(doc_width-am[i]-30);
yp[i] = 0;
stx[i] = 0.02 + Math.random()/10;
sty[i] = 0.7 + Math.random();
doc_width = self.innerWidth;
doc_height = self.innerHeight;
}
dx[i] += stx[i];
document.layers["dot"+i].top = yp[i];
document.layers["dot"+i].left = xp[i] + am[i]*Math.sin(dx[i]);
}
setTimeout("snowNS()", speed);
}

function snowIE()
{ // IE main animation function
for (i = 0; i < no; ++ i)
{ // iterate for every dot
yp[i] += sty[i];
if (yp[i] > doc_height-50)
{
xp[i] = Math.random()*(doc_width-am[i]-30);
yp[i] = 0;
stx[i] = 0.02 + Math.random()/10;
sty[i] = 0.7 + Math.random();
doc_width = document.body.clientWidth;
doc_height = document.body.clientHeight;
}
dx[i] += stx[i];
document.all["dot"+i].style.pixelTop = yp[i];
document.all["dot"+i].style.pixelLeft = xp[i] +
am[i]*Math.sin(dx[i]);
}
setTimeout("snowIE()", speed);
}

if (ns4up) {snowNS();}
else if (ie4up) {snowIE();}
Jul 20 '05 #1
2 2167

"SabMan" <pa****@mts.net> schreef in bericht
news:2c**************************@posting.google.c om...
I understand that document.layers is no longer supported in Netscape
7.1 but I am not sure on how to fix the code so that it will work with
Netscape 7.1.

I understand that document.all is no longer supported in IE6 but I am
not sure on how to fix the code so that it will work with IE6.


It's true that document.layers isn't supported in Nescape 7.1 anymore, but
IE6 still supports document.all

Both Netscape version 6 and higher/Mozilla and IE from version 5.5 support
document.getElementById (IE next to document.all and Netscape/Mozilla
instead of document.layers).

Be aware that since document.getElementById is a function, it should be
called with parentheses at the end and the referenced object should also
contain an ID:

// Object
<div id="some_div" name="some_div">....</div>

// Netscape v4
document.layers['some_div']

// IE
document.all['some_div']

// IE >= v5.5 && Netscape >= v6
document.getElementById('some_div')
JW

Jul 20 '05 #2
pa****@mts.net (SabMan) writes:
I understand that document.layers is no longer supported in Netscape
7.1
Correct. There is no technical connection between Netscape 4 and
Netscape 6+ (based on Mozilla), and the Mozilla people saw no reason
to implement the proprietary layers property in a modern browser.
but I am not sure on how to fix the code so that it will work with
Netscape 7.1.
Rewrite it to use standards.
I understand that document.all is no longer supported in IE6
Incorrect. It works as it always have.
It doesn't work in Mozilla/Netscape 6+.
but I am not sure on how to fix the code so that it will work with
IE6.
Rewrite to use standards. Make sure to put IE 6 into standards mode
using an appropriate DOCTYPE.

I would drop this script completely. It is build specifically to IE4
and Netscape 4, and even that could be done simpler (NS 4 treats
div's with position:fixed as layers, so no need for extra code
to write <layer>).

If you really want to use it, and need it to work in Mozilla/Netscape
6+, use getElementById instead of document.all (if it exists), and
remember to put "px" after the lengths.

if (ns4up)
{ // set layers
if (i == 0)
{
document.write("<layer name=\"dot"+ i +"\" left=\"15\" ");
document.write("top=\"15\" visibility=\"show\"><img src=\"");
document.write(snowflake + "\" border=\"0\"></layer>");
} else
{
document.write("<layer name=\"dot"+ i +"\" left=\"15\" ");
document.write("top=\"15\" visibility=\"show\"><img src=\"");
document.write(snowflake + "\" border=\"0\"></layer>");
}
The branches are identical. No need for the if(i==0) at all.
} else if (ie4up)
{
if (i == 0)
{
document.write("<div id=\"dot"+ i +"\" style=\"POSITION: ");
document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: ");
document.write("visible; TOP: 15px; LEFT: 15px;\"><img src=\"");
document.write(snowflake + "\" border=\"0\"></div>");
} else
{
document.write("<div id=\"dot"+ i +"\" style=\"POSITION: ");
document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: ");
document.write("visible; TOP: 15px; LEFT: 15px;\"><img src=\"");
document.write(snowflake + "\" border=\"0\"></div>");
}
Same here. Also, Netscape 4 understands the div just like the layer,
so you can use this code for both Netscape 4, IE, and all modern browsers.
doc_width = document.body.clientWidth;
doc_height = document.body.clientHeight;
Why is this inside a loop in snowIE? Doing it once should be sufficient.
document.all["dot"+i].style.pixelTop = yp[i];
document.all["dot"+i].style.pixelLeft = xp[i] +


Example: Use
getElement("dot"+i).style.left = yp[i]+(document.layers?"":"px");
where you define:
---
function getElement(id) {
var elem;
if (document.getElementById) {
elem = document.getElementById(id);
} else if (document.all) {
elem = document.all[id];
} else if (document.layers) {
elem = document.layers[id];
}
if (!elem.style) {elem.style = elem;}
return elem;
}
---
This function returns the correct element, no matter what browser, and
if there is no style object on it, it links it to itself.

Good luck.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.