...

View Full Version : Doc type declaration with firefox problem



ryan423
12-13-2004, 10:02 AM
Hi. I'm encountering this error in firefox with this Snow Effect (http://dynamicdrive.com/dynamicindex3/snow.htm) script. Now when I have a transitional DTD <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"> the snow effect does not show on firefox. however, when i remove it then the snow effect shows. it's a problem with this script. does anyone know of a way around it or how to fix it? thanks. by the way, with the transitional DTD, it works fine in internet explorer. just not in firefox.

ryan

ronaldb66
12-13-2004, 01:01 PM
Sounds to me like the browser sniffing they do sort of misses the mark.
Have you tried another doctype, like strict?

Anyway: I think your question is more Javascript then HTML related; I'll ask a moderator to assess this and maybe move the thread. DO NOT crosspost yourself; if it needs to be moved, it will be.

jbot
12-13-2004, 03:23 PM
keep the DTD but remove the URL to the documentation on it, ie just use this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

]|V|[agnus
12-13-2004, 04:05 PM
The URL doesn't point to documentation, it points to the Document Type Definition, the file that defines that document type. Having that URL is sort of one of the whole points of a DOCTYPE declaration to begin with.

My guess is that your script fails with the URL because the browser is then actually conforming to some standard which your script does not. I'd fix the script rather than send a superb browser like Firefox into quirks mode...

ryan423
12-13-2004, 04:19 PM
Well it's not my script, it's from dynamic drive. I'm not adept at javascripting so I wouldn't have any idea on how to fix it. for right now, I don't have a DTD, and I have tried strict DTD but it's the same thing. really weird. without DTD it works. but with it doesn't. and in internet explorer with or without DTD it works. so i'm guessin the firefox browser is not interpreting it properly. It's nice to have this script, since it's christmas and all, but really, what is the whole point of a DTD. If i don't have it, will my page load incorrectly or something? just curious.

P.S.: Without the url link for the DTD, it works. But then what the last poster said was true, how are you going to access the definitions? you minus will not have one.

]|V|[agnus
12-13-2004, 04:28 PM
One of the main ideas of the DOCTYPE declaration is to formally declare the type of document that is about to be processed by the browser. This way it knows what to expect and has a set of rules to follow.

A while back, browsers began implementing a feature called DOCTYPE Switching. The idea here is that the inclusion of a DOCTYPE will trigger "standards mode" in a browser, setting it to follow the rules of the standards. The absences of one triggers what is commonly referred to as "quirks mode" which typically means that it allows for certain errors, tries to assume certain things if details are missing, etc. Basically, trying to be backwards compatible with less-strict, lower quality code.

Odds are much greater that Firefox is in fact doing what a good browser ought to do. IEs covering of so many bases comes from its Microsoft-spawned desire to do everything for you, to try to be smarter than you, rather than letting you be responsible for the code you create.

It is not uncommon for certain things, particularly with scripts, so stop working or behave funny once a browser like Firefox goes into full-on standards mode. This is not because Firefox is broken, but because certain rules were not adhered to by the code author. I can't say for certain what the case is with you, but all of this is generally good information nonetheless. Though, if I've fudged any details, I welcome corrections from other forum members.

ryan423
12-13-2004, 04:35 PM
But i find it hard to understand. why would one simple link disrupt the flow of a script. it there like a specific way to write scripts or something?

]|V|[agnus
12-13-2004, 04:51 PM
Well, this doesn't pertain to what you're doing, but it is an example of what I'm referring to:

The document.write() method in JavaScript is not supported in XML, so browsers that are sent XML and are rendering in standards mode will not honor calls to document.write(). Basically, it will not work.

So, since the presence of a valid DOCTYPE is enough to put many browsers in "standards mode", that might be what's causing the script not to work. Why? I'm not sure. I just glanced at that script's page, and off the bat I see:

<script language="Javascript 1.2">

The language attribute is deprecated(no longer valid, not to be used) so that might invalidate the entire script in Firefox right there. The preferred format now is:

<script type="text/javascript">

The idea being that if your script requires a certain level of JavaScript, that you will test for the presence of supported objects or methods, rather than supposed support for an entire version of the language. Many times browser will claim support for an entire standard while only getting parts of it right.

But I am digressing a bit, and perhaps confusing things more. If so, I apologize.

jbot
12-13-2004, 06:34 PM
|V|[agnus']The URL doesn't point to documentation, it points to the Document Type Definition, the file that defines that document type.

that's wot i meant - dinnae be pedantic, man. :rolleyes:

]|V|[agnus
12-13-2004, 06:38 PM
There's a significant difference in the wording you chose. It's a relevant distinction to make.

Puffin the Erb
12-13-2004, 08:32 PM
That is WEIRD....

It works in Netscape 4 - now that is weird ! :)

hemebond
12-13-2004, 10:07 PM
48880.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>48880</title>
<style type="text/css">
.flake {
position:absolute;
z-index:2;
}
</style>
</head>
<body>
<script type="text/javascript" src="48880.js"></script>
<script type="text/javascript">
var generator = new Generator("images/snow.gif", 20);
</script>
</body>
</html>48880.js
function Flake(image)
{
this.age = 0;

this.x = Math.random() * ( window.innerWidth - 50 );
this.y = Math.random() * window.innerHeight;

this.amplitude = Math.random() * 20;

this.stepX = 0.02 + Math.random() / 10;
this.stepY = 0.7 + Math.random();

this.image = document.createElement("img");
this.image.setAttribute("src",image);
this.image.setAttribute("class","flake");

this.image.style.left = this.x + "px";
this.image.style.top = this.y + "px";

document.getElementsByTagName("body")[0].appendChild(this.image);

this.think = think;
this.reset = reset;
}

function think()
{
this.y += this.stepY;

if (this.y > window.innerHeight - 50)
{
this.reset();
}
this.age += this.stepX;

this.image.style.top = this.y + "px";
this.image.style.left = (this.x + this.amplitude * Math.sin( this.age )) + "px";
}

function reset()
{
this.x = Math.random() * (window.innerWidth - this.amplitude - 30);
this.y = 0;
this.stepX = 0.02 + Math.random() / 10;
this.stepY = 0.7 + Math.random();
}

function Generator(image, quantity)
{
this.Flakes = new Array();

for(var i = 0; i < quantity; i++)
{
this.Flakes[i] = new Flake(image);
}

this.update = update;

setInterval("generator.update()",10);
}

function update()
{
for(var i = 0; i < this.Flakes.length; i++)
{
this.Flakes[i].think();
}
}I can't figure out how to make and object call it's own method regularly. Also, can anyone see any way to make this more OOP?

It doesn't look like I can get this to work in IE, it has a problem with
this.image.style.left = this.x + "px";Can anyone see a problem with that line?

jbot
12-13-2004, 11:08 PM
It works in Netscape 4 - now that is weird !

no, it's not. i used that script once on a website. the only downside is that it slows your machine and server down. not really a good idea.

Puffin the Erb
12-14-2004, 06:35 PM
Hemebond,
I don't think innerHeight and innerWidth are part of IE's window object.

hemebond
12-14-2004, 08:06 PM
Hemebond,
I don't think innerHeight and innerWidth are part of IE's window object.You're right. I've made these two functions to replace those instances
function getWindowWidth()
{
if(window.innerWidth)
{
return window.innerWidth;
}
else
{
return document.body.offsetWidth;
}
}

function getWindowHeight()
{
if(window.innerHeight)
{
return window.innerHeight;
}
else
{
return document.body.offsetHeight;
}
}But there are still errors and the debugger locked up on me. Anyone else care about IE enough to help?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum