Problems with Netscape


A

ALuPin

Hi,

when I try to see the effect of the following script
I do not see anything when using Netscape Navigator whereas
InternetExplorer ist ok.

In Netscape Javascript is activated. What could be the problem?

Thank you for your help.


<head>
<STYLE>.spanstyle {
COLOR: green; FONT-FAMILY: Verdana; FONT-SIZE: 10pt;
FONT-WEIGHT: bold; POSITION: absolute; TOP: -50px; VISIBILITY: visible
}
</STYLE>
<SCRIPT>
var x,y
var step=20
var flag=0
//
var message="THIS IS A TEST!!"
message=message.split("")
var xpos=new Array()
for (i=0;i<=message.length-1;i++) {
xpos=-50
}
var ypos=new Array()
for (i=0;i<=message.length-1;i++) {
ypos=-50
}
function handlerMM(e){
x = (document.layers) ? e.pageX :
document.body.scrollLeft+event.clientX
y = (document.layers) ? e.pageY :
document.body.scrollTop+event.clientY
flag=1
}
function makesnake() {
if (flag==1 && document.all) {
for (i=message.length-1; i>=1; i--) {
xpos=xpos[i-1]+step
ypos=ypos[i-1]
}
xpos[0]=x+step
ypos[0]=y
for (i=0; i<message.length-1; i++) {
var thisspan = eval("span"+(i)+".style")
thisspan.posLeft=xpos
thisspan.posTop=ypos
}
}
else if (flag==1 && document.layers) {
for (i=message.length-1; i>=1; i--) {
xpos=xpos[i-1]+step
ypos=ypos[i-1]
}
xpos[0]=x+step
ypos[0]=y
for (i=0; i<message.length-1; i++) {
var thisspan = eval("document.span"+i)
thisspan.left=xpos
thisspan.top=ypos
}
}
var timer=setTimeout("makesnake()",30)
}
</SCRIPT>
</head>
<body onload="makesnake()" style="OVERFLOW-X: hidden; OVERFLOW-Y:
scroll; WIDTH: 100%" BACKGROUND>
<SCRIPT>
<!-- Beginning of JavaScript -
for (i=0;i<=message.length-1;i++) {
document.write("<span id='span"+i+"' class='spanstyle'>")
document.write(message)
document.write("</span>")
}
if (document.layers){
document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = handlerMM;
// - End of JavaScript - -->
</SCRIPT>
</body>
</html>
 
Ad

Advertisements

L

Lasse Reichstein Nielsen

when I try to see the effect of the following script
I do not see anything when using Netscape Navigator whereas
InternetExplorer ist ok.
In Netscape Javascript is activated. What could be the problem?

Probably you using proprietary IE features. Let's have a look

function handlerMM(e){

Looks like an event handler. That would mean that the 'e' is the event
in non-IE browsers (whereas IE keeps the event as the global variable
"event").
x = (document.layers) ? e.pageX :
document.body.scrollLeft+event.clientX

And right on, if document.layers exists, then "e" is used, otherwise
"event" is used. However, Netscape 6+ doesn't have a document.layers
object, but it should use the "e" varible, so this code fails completely.

It looks like it was written for IE and Netscape 4 exclusively, and
therefore it fails in all other browsers.
function makesnake() {
if (flag==1 && document.all) {

this test for "document.all" is probably meant to detect IE. That is
no longer the case. Other browsers, e.g., Opera, also has document.all
collections.
var thisspan = eval("span"+(i)+".style")

This is blatant misuse of eval, as well as IE specific coding.

If "i" is, e.g., 2, then this will evaluate the expression
"span2.style". I assume "span2" is the id/name of a span element. IE
makes global variables available that refer to named elements. Other
browsers does not.

It could just be written as:
window["span"+i]
in IE, and it would even be faster.
var thisspan = eval("document.span"+i)

This accesses "document.span2". It could just be written as:
document["span"+i];

Neither of these two access methods ("window['span'+i]" or
"document['span'+i]") will work in Netscape 6+. Instead you should use
"document.getElementById('span'+i)"
<body onload="makesnake()" style="OVERFLOW-X: hidden; OVERFLOW-Y:
scroll; WIDTH: 100%" BACKGROUND>

OVERFLOW-X and OVERFLOW-Y are prorietary IE features. The background
attribute should have a value.

The "type" attribute is required on script tags in HTML 4. Use
<!-- Beginning of JavaScript -

This line is not needed.

/L
 
Ad

Advertisements

R

Richard Cornford

ALuPin said:
when I try to see the effect of the following script
I do not see anything when using Netscape Navigator whereas
InternetExplorer ist ok.

In Netscape Javascript is activated. What could be the problem?
function makesnake() {
if (flag==1 && document.all) {
var thisspan = eval("span"+(i)+".style")

Any script author who uses - eval - to resolve a dot notation property
accessor doesn't really understand javascript. Unsurprisingly people who
don't understand javascript don't tend to create very good scripts, so
expecting the results to be cross-browser or reliable is probably
unrealistic.

else if (flag==1 && document.layers) {
<snip>

This script has an - if(document.all){ - branch, which will be taken by
IE, Opera, Konqueror, Safari, IceBrowser and others. It also has an -
else if(document.layers) - branch, which would be followed by Netscape 4
and a couple of close imitators. But Netscape 6+ dropped the -
document.layers - collection in favour of implementing W3C DOM standards
and so there is no branch in this code that will be taken by Netscape
6+, Mozilla or any other Gecko-based browser.

The balance of probability is that this is a script from some published
copy-and-paste collection and was written at the time when IE 4 and
Netscape 4 were the dominant scriptable browsers, but is now out of date
(in its browser scripting and implementation style). That is the problem
with copy-and-paste scripts (apart from the lack of any qualified
quality control overseeing their publication); once they have been
placed on the Internet there they stay, a trap for the unwary and
contributing to making the internet worse when they find themselves
being used by people who don't know any better and only superficially
test in one browsers.

Richard.
 

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

Top