Forum Moderators: open

Message Too Old, No Replies

xhtml strict

browser problems

         

benihana

8:49 am on Aug 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



in another thread [webmasterworld.com]

someone says something along the lines of xhtml strict dtd causing browser problems.

acouple of sites im working on at the moment use valid xhtml strict, and i havent noticed any problems in the browsers ive checked so far.

does any one have any further info?
thanks

Hester

9:04 am on Aug 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



See my comment in that thread.

benihana

9:15 am on Aug 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ok. the xml declaration issues?

thought it was something else i was missing..
thanks hester

Hester

9:39 am on Aug 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



AFAIK there shouldn't be any other problems, but I could be wrong.

encyclo

12:06 pm on Aug 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I know of no particular problems with using the XHTML Strict doctype, other than the XML prolog issue with IE6 which equally affects XHTML 1.0 Transitional.

As tedster and others have mentioned previously, the most important difference is between Transitional and Strict, not between HTML and XHTML.

Perhaps the poster was referring to XHTML 1.1, which should generally not be used?

Lance

7:45 pm on Aug 10, 2004 (gmt 0)

10+ Year Member



Perhaps the poster was referring to XHTML 1.1, which should generally not be used?

Why should XHTML 1.1 not be used?

BjarneDM

9:48 pm on Aug 10, 2004 (gmt 0)

10+ Year Member



IE 5.0, 5.5 and 6.0 can't understand any version of xhmtl or xml strictly according to the standards. They all treat xhtml as some kind of malformed html 4.01. That's because they can only understand the mime-type text/html and go completely bonkers if served with the mime-type that as per the standard should be application/xhtml+xml.

xhtml 1.0 in html compatible mode is a *** that shouldn't have been invented.

see the following:
[xml.com...]
[w3.org...]
[hixie.ch...]
[devedge.netscape.com...]

you are asking for serious trouble if you want xhtml to work in IE x.x.
don't use xhmtl - use html 4.01 and avoid any problems.

the focus in developer circles on xhmtl as the holy grail is in my opinion completely misunderstood when you have to continuously compromise your coding in order to cater for IE x.x

[edited by: eelixduppy at 9:44 pm (utc) on Feb. 18, 2009]

drbrain

10:04 pm on Aug 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It has to do with MIME types.

XHTML served as text/html (ok with xhtml1.0, not with xhtml1.1) will probably work just fine (See BjarneDM's post for details).

XHTML served with an XML MIME type (application/xhtml+xml, text/xml) will cause some breakage. For example, document.write no longer works. You must use the DOM to add content to a page.

IE6 does not explicitly support XHTML, but it does support XML and styling of XML with CSS, so you can have a fully functional XHTML2 example [w3future.com] in IE6.

Lance

10:35 pm on Aug 10, 2004 (gmt 0)

10+ Year Member



Interesting...

Because I didn't know any better, I've been redesigning a site I'm working on to be XHTML 1.1 compliant, and it verifies just peachy. It also looks and works fine in IE 6.0, and I'm not concerned with IE <6. It is being served as text/html. What kind of problems am I in for?

drbrain

10:48 pm on Aug 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When you switch over to an XML MIME type, you may find that your pages that worked as HTML now fail because they are not well-formed.

g1smd

10:57 pm on Aug 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Probably loads, especially in newer browsers coming out later (like in handheld and mobile devices).

Summery: XHTML 1.1 MUST NOT be served as "text/html".

Lance

11:09 pm on Aug 10, 2004 (gmt 0)

10+ Year Member



Okay, I do believe you, but then why does it validate okay? (sorry if that is a stupid question)

And I'm sorry for this stupid question as well...

My pages are all ASP. To change the mime type on my server, I would have to change it for the ASP extension, correct? It seems that would break other things, but I don't know until I try I suppose.

<added>
Okay, I changed the mime type on the server to "application/xhtml+xml". It still seems to be working fine in IE6+ and NN7.1. What should I be looking for?
</added>

<second edit>
Also changed the meta tag:
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
Still no problem found.
</second edit>

drbrain

11:35 pm on Aug 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you validate your page every time you add a new page, you'll probably be just fine. The validator is not 100% perfect at parsing XML, so you'll want to watch out for these problems:

[openjade.sourceforge.net...]

(linked from the validator's "you validate" page)

Read also BjarneDM's link to hixie.ch

Lance

12:05 am on Aug 11, 2004 (gmt 0)

10+ Year Member



Perhaps my best solution is to continue to code and validate against XHTML 1.1, but then ultimately publish in XHTML 1.0 Strict and serve as text/html which seems to be acceptable.

encyclo

11:46 am on Aug 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK I admit I made an unqualified comment about XHTML 1.1 then switched off the computer for the day. I'll try to clarify.

Firstly, Lance, if your site is displaying in IE6, then you are not serving it as

application/xhtml+xml
- check the page info in Mozilla and it will tell you the mime type currently used. The meta tag won't do anything as the page has already been given a mime type once you've got to there. Internet Explorer cannot display
application/xhtml+xml
at all.

but then why does it validate

Because the validator does not check mime types - only well-formedness.

BjarneDM is not wrong but rather alarmist - XHTML 1.0 should be served as

application/xhtml+xml
, but may be served as
text/html
. Doing the latter won't cause any problems in older browsers (but you get no real advantage over HTML 4).

Back to XHTML 1.1. People tend to choose it because they see it as the latest W3C recommendation, and that it is the "strictest" standard with no depreated elements.

However, XHTML 1.1 is not actually the most up-to-date standard - XHTML 1.0 Second Edition came out afterwards with numerous errata and a few added features such as allowing an

id
attribute on the
html
element - useful if you are styling that element in CSS. XHTML 1.1 was created as part of the XHTML modularization initiative, was split off before XHTML 1.0 Second Edition and thus does not include such changes.

The role of XHTML 1.1 was to be an XHTML module to be used in combination with other XML types - for example, XHTML + SVG, or XHTML + MathML. It is not designed as a standalone application (although it can be used as such). Also, the lack of certain depreciated elements can mean that an XHTML 1.1 page is less accessible than an XHTML 1.0 page - for example, the

lang
attribute can be used in XHTML 1.0 to identify the document language to screenreaders, etc. - however, you only have
xml:lang
in XHTML 1.1, which is not widely recognized.

Finally, the virtually intractible question of acceptable mime-types for XHTML 1.1. Reading the documentation on the W3C website, there are two conflicting pieces of advice - one which says that XHTML 1.1 absolutely cannot be served as

text/html
, and elsewhere saying that it should not, but may. In fact, there is no consensus regarding this question within the W3C, and so it is impossible to implement an XHTML 1.1 page served as
text/html
and be sure that it is fully-standards-compliant.

XHTML 1.1 is the wrong standard with a lack of clarity in its specification, and has been superceded by XHTML 1.0 Second Edition. Best avoided.

Finally, it's only markup - using validated XHTML 1.1 served as

text/html
is still far better than using Yahoo-style tag soup. You're still way ahead of the vast majority of other sites. Me, I much prefer HTML 4, but if you prefer XHTML, that's fine too.

Lance

5:35 pm on Aug 11, 2004 (gmt 0)

10+ Year Member



encyclo;

Thank you for the very infomative post.

Firstly, Lance, if your site is displaying in IE6, then you are not serving it as application/xhtml+xml - check the page info in Mozilla and it will tell you the mime type currently used. The meta tag won't do anything as the page has already been given a mime type once you've got to there. Internet Explorer cannot display application/xhtml+xml at all.

Absolutely correct. It seems none of the actions I took server-side (IIS) caused the pages to be served application/xhtml+xml. I have since found an ASP script that detects browser capabilities and will serve appropriately. For testing, I disabled detection and just forced the site to be served application/xhtml+xml.

As expected, IE bailed completely and NN became unhappy. Surprisingly though, if I had the page already loaded in IE, then activated the new MIME type on the server and reloaded the page in IE, it fouled up less than NN did. I realize this is not really a valid test though.

Back to XHTML 1.1. People tend to choose it because they see it as the latest W3C recommendation, and that it is the "strictest" standard with no depreated elements.

Guilty...

Okay, back to XHTML 1.0 it is. For the mean time, with 1.0 it is legal to serve text/html, so I can leave it that way until I'm ready to work out everything that broke in NN when served application/xhtml+xml.

Thanks again.

-Lance

zaptd

6:09 pm on Aug 11, 2004 (gmt 0)

10+ Year Member



XHTML 1.0 Second Edition came out afterwards with numerous errata and a few added features such as allowing an id attribute on the html element - useful if you are styling that element in CSS.

Incorrect. The id attribute on the HTML element has always been allowed for the Transitional DTD: [w3.org...]
It is not (and never was) an allowed attribute for the html element in the Strict DTD:
[w3.org...]

Reading the documentation on the W3C website, there are two conflicting pieces of advice - one which says that XHTML 1.1 absolutely cannot be served as text/html, and elsewhere saying that it should not, but may.

Incorrect. Developers confuse a 'should not' with a 'may,' but the W3C has been consistent in their recommendations.

XHTML 1.1 is the wrong standard with a lack of clarity in its specification, and has been superceded by XHTML 1.0 Second Edition

In your opinion. Where does the W3C state this?

I agree that XHTML 1.0 is more backwards compatible.

HTH,
CK

encyclo

8:18 pm on Aug 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The id attribute on the HTML element ... is not (and never was) an allowed attribute for the html element in the Strict DTD

If you cut-and paste this:

<?xml version="1.0" encoding="utf-8"?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" id="my-choice-of-id">
<head>
<title>Try me</title>
</head>
<body>
<h1>ID on HTML element</h1>
<p>This page is valid XHTML 1.0 Strict</p>
</body>
</html>

You will find that it validates. Swap the XHTML 1.0 Strict doctype for the XHTML 1.1 one, and it doesn't.

References:

Lance, when you serve pages as application/xhtml+xml, there are changes in the way the document is parsed and in the way CSS and Javascript function. If you are using CSS extensively, you will notice that styles applied to the body tag don't affect the whole page, just the content area, for example. You should try shifting rules up to the html element for starters. Also make absolutely sure of your capitalization. For Javascript, certain scripts won't work - including anything using document.write (eg. Adsense).

If you are interested in serving pages as application/xhtml+xml to those browsers that can cope with it, you need to read the HTTP_ACCEPT header and parse it for application/xhtml+xml. That means that IE, Googlebot and older browsers will get text/html and browsers such as Opera and Mozilla get the appropriate mime type. I've seen some ASP code around which does this - if I find it, I'll post it (I only use PHP myself).

Don't forget that when you are serving documents as application/xhtml+xml, one well-formedness error, however minor, and your page won't display at all - you'll just see an XML error. You have been warned!

zair

12:14 am on Aug 12, 2004 (gmt 0)

10+ Year Member



A problem I've been having with XHTML strict lies in its lack of support for the TARGET attribute (like target="top" and all that)! I built/copied a dtd file to make up for that by adding the xhtml 1.1 target module, but I'm wondering how that's going to affect the display in IE?

Also, it validates as okay based on the dtd, but is it still XHTML 1.0 strict?

Anybody else have experience with that?

Lance

12:57 am on Aug 12, 2004 (gmt 0)

10+ Year Member



Here is the ASP script that sends appropriate headers:


<%
Accept = Request.ServerVariables("HTTP_ACCEPT")
UA = Request.ServerVariables("HTTP_USER_AGENT")
If InStr(Accept, "application/xhtml+xml") > 0 OR InStr(UA, "W3C_Validator") > 0 Then
Response.ContentType = "application/xhtml+xml"
Response.Write("<?xml version=""1.0"" encoding=""utf-8""?>" & VbCrLf)
Else
Response.ContentType = "text/html"
End If
Response.Charset = "utf-8"
%>

And this replaces target="_whatever":


function ExternalLinks() {
/*Links Like This: <a href="http://www.foo.com" rel="external"> */
/*And Call onLoad: window.onLoad=externalLinks; */
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
anchor.target = "_blank";
}
}

BjarneDM

7:03 am on Aug 12, 2004 (gmt 0)

10+ Year Member



I've had problems checking for application/xhmtl+xml.

Safari and Konqueror as well as the w3c validator don't send that in their http-accept string (as also evidenced in the asp script). Safari for instance is sending */* (I can handle everything), so I've decided on some other tests. This is my php script:


<?php
if ( stristr($_SERVER["HTTP_USER_AGENT"],"Mozilla/4.0") &&
!stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") )
{


header("Content-type: text/html");?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="da">

<?php else {


header("Content-type: application/xhtml+xml");?>
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="/css/mozilla.css" type="text/css"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://mozilla.mathiesen.info/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">


<?php }?>

I assume that every user agent greater than Mozilla/4.0 (Mozilla, Safari, Konqueror and Opera are sendig Mozilla/5.0) is able to handle application/xhtml+xml and then do a check for if a 4.0 browser should be able to handle application/xhtml+xml

Hester

8:31 am on Aug 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Incorrect. The id attribute on the HTML element has always been allowed for the Transitional DTD: [w3.org...]
It is not (and never was) an allowed attribute for the html element in the Strict DTD:
[w3.org...]

I always thought it was the other way round. But checking the links you gave, both say ID is "implied" on the HTML tag.

isitreal

6:50 am on Aug 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Encyclo, great posts, I added some comments [webmasterworld.com] in this thread about javascript problems with real XHTML.

I have been unable to find solutions to such simple problems in repeeated web searches, so I assume they are not well solved yet.

I do notice that people doing xhtml strict basically are just avoiding the problems by not using those techniques: ie, use the newest and greatest and have fewer options, less versatility, and more headaches. Sounds like a real winnner.....