473,326 Members | 2,061 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,326 software developers and data experts.

changing doctype changes javascript behavior in FF?

I have a page that uses this doctype
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

but when I change to this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

it breaks my javascript. Particularly I have a code that try to set
element.style.left, when I use the second doctype, FF complains "Error
in parsing value for property 'left'. Declaration dropped"
I turns out that I was setting it to just integer number before, and
when I use the second doctype you have to set it with the unit as well.

So instead of:
element.style.left = 25;

you have to do:
element.style.left = '25px';

I thought it really was a weird behavior. Is there any other case where
changing the doctype changes js behavior?

Jun 12 '06 #1
6 2257


reynard wrote:
So instead of:
element.style.left = 25;

you have to do:
element.style.left = '25px';

I thought it really was a weird behavior.


IE5/Mac started that doctype sniffing and working in so called quirks
mode versus standard compliants mode or strict mode depending on the
doctype. By now Mozilla, Opera and IE 6/Win all do that sniffing and
have different rendering modes.
CSS requires you to have a number plus a unit for the left property so
if you use a doctype that puts Mozilla in standards compliant mode
Mozilla's CSS parser ignores values which are not complying with the CSS
specification (both in static CSS stylesheets as well as when script
manipulate CSS values).
See <http://developer.mozilla.org/en/docs/Mozilla%27s_DOCTYPE_sniffing>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 12 '06 #2
"reynard" <re*******@gmail.com> writes:
I have a page that uses this doctype
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

but when I change to this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

it breaks my javascript.
That change most likely causes the browser to switch to standards
compliant mode. If that breaks your script, I'd say the script was
already broken by relying on non-standard browser behavior.
I turns out that I was setting it to just integer number before, and
when I use the second doctype you have to set it with the unit as well.

So instead of:
element.style.left = 25;

you have to do:
element.style.left = '25px';
It's not really javascript that is changed here, but CSS
interpretation. The first assignment converts 25 to a string and
assigns it to the "left" CSS property. That is not a valid CSS
value, but in "quirks" mode, the browser chooses to accept it anyway,
with a default unit of "px" applied.

In standards comliant mode, the incorrect CSS value is, correctly,
rejected.
I thought it really was a weird behavior. Is there any other case where
changing the doctype changes js behavior?


There are a few. My two first thoughts when I read the first sentence
of your post was missing CSS units and document.documentElement.

In standards mode, the root of the document is document.documentElement,
whereas in quirks mode, that element might be missing, and document.body
is the root element of all displayed elements.

You can read more about standards/quirks mode and the effect of
changing the DOCTYPE in the links here:
<URL:http://www.infimum.dk/HTML/references.html#ref_1_6>

/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.'
Jun 12 '06 #3
thanks for the explanation and the link. it's really helpful to know
that.

- reynard

Martin Honnen wrote:

IE5/Mac started that doctype sniffing and working in so called quirks
mode versus standard compliants mode or strict mode depending on the
doctype. By now Mozilla, Opera and IE 6/Win all do that sniffing and
have different rendering modes.
CSS requires you to have a number plus a unit for the left property so
if you use a doctype that puts Mozilla in standards compliant mode
Mozilla's CSS parser ignores values which are not complying with the CSS
specification (both in static CSS stylesheets as well as when script
manipulate CSS values).
See <http://developer.mozilla.org/en/docs/Mozilla%27s_DOCTYPE_sniffing>

--

Martin Honnen
http://JavaScript.FAQTs.com/


Jun 12 '06 #4
reynard wrote:
I have a page that uses this doctype
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
I'm not 100% certain, but I don't believe this is a valid doctype...
- yep, just checked: http://www.w3.org/QA/2002/04/valid-dtd-list.html#DTD
but when I change to this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

it breaks my javascript.
More likely that your javascript's broken.
Particularly I have a code that try to set
element.style.left, when I use the second doctype, FF complains "Error
in parsing value for property 'left'. Declaration dropped"
I turns out that I was setting it to just integer number before, and
when I use the second doctype you have to set it with the unit as well.

So instead of:
element.style.left = 25;
(which is incorrect)
you have to do:
element.style.left = '25px';
(which is correct)
I thought it really was a weird behavior. Is there any other case where
changing the doctype changes js behavior?


javascript's behavior isn't changed, but the browser's response to the
CSS you're defining has changed - and you can expect that to happen in
other cases when you change doctype, especially if you aren't writing it
correctly in the first place.

Any particular reason not to use STRICT?
--
"The most convoluted explanation that fits all the available and made-up
facts is the most likely to be believed by conspiracy theorists"
Jun 12 '06 #5
Tony <to****@dslextreme.WHATISTHIS.com> writes:
reynard wrote:
I have a page that uses this doctype
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


I'm not 100% certain, but I don't believe this is a valid doctype...
- yep, just checked: http://www.w3.org/QA/2002/04/valid-dtd-list.html#DTD


It's valid. The system identifier (the URL) is optional.

/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.'
Jun 12 '06 #6
Lasse Reichstein Nielsen <lr*@hotpop.com> writes:
Tony <to****@dslextreme.WHATISTHIS.com> writes:
reynard wrote:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
I'm not 100% certain, but I don't believe this is a valid doctype...


Assuming the reference concrete syntax, what would _not_ be *valid*
about it? (Even if the formal public identifier were unknown, a
system's catalog could be set up to know better, and otherwise the
document instance set would be invalid, not the document type
declaration.)
It's valid. The system identifier (the URL) is optional.


For conforming SGML applications, yes (and so is the FPI). HTML 4.01
isn't one, as section 7.2 implicitly proclaims, and it is fair enough to
mention (even in a javascript group :) that user agents don't treat it
as one either but invite for voodoo feature switching instead (which
actually appears to be the 'problem' here, but *that* is not about
client-side scripting indeed).
--
||| hexadecimal EBB
o-o decimal 3771
--oOo--( )--oOo-- octal 7273
205 goodbye binary 111010111011
Jun 13 '06 #7

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

Similar topics

31
by: Arthur Shapiro | last post by:
I'm the webmaster for a recreational organization. As part of one page of the site, I have an HTML "Calendar at a Glance" of the organization's events for the month. It's a simple table of a...
31
by: Greg Scharlemann | last post by:
Given some recent success on a simple form validation (mainly due to the kind folks in this forum), I've tried to tackle something a bit more difficult. I'm pulling data down from a database and...
2
by: DartmanX | last post by:
I doubt this is possible, but I want to ask, just in case it is. I have a project going using Google Maps. This project spits out an HTML page template for people to post to their website and...
17
by: Rick Brandt | last post by:
We are using a JS popup calendar in our pages and find that we get various JS errors whenever we call the code from an HTML page that includes a DOCTYPE. The specific type doesn't seem to matter. ...
1
by: Blasting Cap | last post by:
I am having trouble changing the font for a PushButton control in a datagrid button column. I have seen several posts refer to styles and simple changes to the HTML for font changes but most of...
3
by: John | last post by:
Hi I have been trying to change the css class of a linkbutton without succes ( I dont want to change the cssclass property). Maybe somebody knowshow to do this?? th.John <%@ Page...
3
by: cbradio | last post by:
Hi, I am having trouble developing a form in a restricted environment. My sample code is found below my message (sorry I don't have a URL). Basically, without a doctype, the form displays properly...
16
by: vunet.us | last post by:
Hm... I used to have a function which drags some div element on mousemove. After I added: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://...
3
by: Stephen Ward | last post by:
I have a simple little project open a xml file change a few nodes save the file, no big deal. The problem is that the doctype is getting modified when I save the file. So it looks like this:...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.