473,657 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.innerHeigh t;
}
else if (ie4up)
{
alert("here");
doc_width = document.body.c lientWidth;
doc_height = document.body.c lientHeight;
}
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()*d oc_height;
am[i] = Math.random()*4 0; // 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=\"sh ow\"><img src=\"");
document.write( snowflake + "\" border=\"0\"></layer>");
} else
{
document.write( "<layer name=\"dot"+ i +"\" left=\"15\" ");
document.write( "top=\"15\" visibility=\"sh ow\"><img src=\"");
document.write( snowflake + "\" border=\"0\"></layer>");
}
} else if (ie4up)
{
if (i == 0)
{
document.write( "<div id=\"dot"+ i +"\" style=\"POSITIO N: ");
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=\"POSITIO N: ");
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.innerHeigh t;
}
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("sno wNS()", 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.c lientWidth;
doc_height = document.body.c lientHeight;
}
dx[i] += stx[i];
document.all["dot"+i].style.pixelTop = yp[i];
document.all["dot"+i].style.pixelLef t = xp[i] +
am[i]*Math.sin(dx[i]);
}
setTimeout("sno wIE()", speed);
}

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

"SabMan" <pa****@mts.net > schreef in bericht
news:2c******** *************** ***@posting.goo gle.com...
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.getEle mentById (IE next to document.all and Netscape/Mozilla
instead of document.layers ).

Be aware that since document.getEle mentById 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.getEle mentById('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=\"sh ow\"><img src=\"");
document.write( snowflake + "\" border=\"0\"></layer>");
} else
{
document.write( "<layer name=\"dot"+ i +"\" left=\"15\" ");
document.write( "top=\"15\" visibility=\"sh ow\"><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=\"POSITIO N: ");
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=\"POSITIO N: ");
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.c lientWidth;
doc_height = document.body.c lientHeight;
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.pixelLef t = xp[i] +


Example: Use
getElement("dot "+i).style. left = yp[i]+(document.laye rs?"":"px");
where you define:
---
function getElement(id) {
var elem;
if (document.getEl ementById) {
elem = document.getEle mentById(id);
} else if (document.all) {
elem = document.all[id];
} else if (document.layer s) {
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/rasterTriangleD OM.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
3657
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
0
8425
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8326
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8743
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8522
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8622
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5647
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2745
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1973
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.