views:

47

answers:

3

We've built a javascript based widget that our client has embedded in their website. They claim it doesn't work on their site in IE7, and that the problem is the difference in doctype headers at the top of their pages:

Ours:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

Theirs:

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

Is there any difference in these two headers, and how they would effect performance in IE7?

Thanks-

+2  A: 

Depends on how it is broken. JS doesn't care about the DOCTYPE, but the HTML of the widget might. There are differences but it's far more likely that the problem is quirks mode vs standards mode.

Here is a chart of which DOCTYPEs trigger which modes in various browsers

Rob
Precisely, the doctype can trigger quirks or standard mode. http://en.wikipedia.org/wiki/Quirks_mode
Savageman
I believe that either DOCTYPE should trigger standards mode, and then the page is probably breaking standards
Rob
JS **does** care about quirks/standards mode, and HTML 4.01 Transitional with no URI triggers quirks mode.
David Dorward
In what way does JS care about quirks vs standards mode? To JS it is all parsed DOM.
Rob
Different bugs are exposed in the JS DOM API depending on mode. (I wouldn't be surprised if there were core JS differences too, but I don't know of any off the top of my head)
David Dorward
The changes are to DOM and rendering, not JS. The JS engine is the same. http://stackoverflow.com/questions/1503843/quirksmode-javascript-implementation
Rob
Switching `setAttribute` between broken and standard has nothing to do with rendering, not does the change in `getElementById('foo')` returning `<a name='foo'>...</a>`.
David Dorward
@Rob- looks like the second header was triggering quirks mode. Thank you for the chart- very helpful.
Yarin
A: 

IE has been a huge culprit for having problems when doctypes arent set properly or arent showing up properly. I havent seen ie 7 doing it that often, but i know IE 6 was terrible. Are you able to declare what the doctype is?

Ascherer
We can't touch the doctype as it is the client's site, and we are just delivering a widget. Thanks.
Yarin
+1  A: 

The second doctype will trigger Quirks mode in IE. In this mode it emulates a number of bugs from IE 5.x so that it can be compatible with 199x era websites.

This has a wide range of effects and includes such things as getting the meaning of width in CSS wrong (fixed from IE6 onwards but only in standards mode) and getting setAttribute wrong (fixed from IE8 onwards, but only in standards mode).

David Dorward
This seems to be it. The specific issue ended up being that an absolutely positioned div with style="left:0px;right:0px" ended up collapsing to nothing, and the fix was to specify an explicit width.
Yarin