Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    New Coder
    Join Date
    Jul 2004
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Doc type declaration with firefox problem

    Hi. I'm encountering this error in firefox with this Snow Effect 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

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    The Netherlands, Baarn, Ut.
    Posts
    4,253
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Browser sniffing

    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.
    Regards,
    Ronald.
    ronaldvanderwijden.com

  • #3
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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">
    *keep it simple (TM)

  • #4
    Regular Coder
    Join Date
    May 2004
    Location
    Minneapolis, MN, USA
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...

  • #5
    New Coder
    Join Date
    Jul 2004
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Last edited by ryan423; 12-13-2004 at 04:24 PM.

  • #6
    Regular Coder
    Join Date
    May 2004
    Location
    Minneapolis, MN, USA
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #7
    New Coder
    Join Date
    Jul 2004
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #8
    Regular Coder
    Join Date
    May 2004
    Location
    Minneapolis, MN, USA
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Last edited by ]|V|[agnus; 12-13-2004 at 04:54 PM.

  • #9
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ]|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.
    *keep it simple (TM)

  • #10
    Regular Coder
    Join Date
    May 2004
    Location
    Minneapolis, MN, USA
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts
    There's a significant difference in the wording you chose. It's a relevant distinction to make.

  • #11
    Regular Coder
    Join Date
    Oct 2004
    Posts
    168
    Thanks
    0
    Thanked 5 Times in 5 Posts
    That is WEIRD....

    It works in Netscape 4 - now that is weird !
    Last edited by Puffin the Erb; 12-13-2004 at 09:21 PM.

  • #12
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    48880.html
    Code:
    <!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
    Code:
    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
    Code:
    	this.image.style.left = this.x + "px";
    Can anyone see a problem with that line?

  • #13
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Puffin the Erb
    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.
    *keep it simple (TM)

  • #14
    Regular Coder
    Join Date
    Oct 2004
    Posts
    168
    Thanks
    0
    Thanked 5 Times in 5 Posts
    Hemebond,
    I don't think innerHeight and innerWidth are part of IE's window object.

  • #15
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Puffin the Erb
    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
    Code:
    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?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •