Quote:
|
Originally Posted by weslinda
Interesting point, so what language should we all work in as designers?
|
We should be using xhtml1.1 as it is the latest of the w3c standards. Just because the most popular browser does not properly support xhtml is no reason not to adopt it.
Writing xhtml1.1 for any browser without sending a proper application/xhtml+xml header is just writing "tag soup" and will be treated as "Content-type: text/html" so you need to use some server side programming to determine what the browser supports and send it a header it supports.
If you send the following xml prolog and dtd
Code:
<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
without sending a header("Content-type: application/xhtml+xml"); Internet explorer will by default treat it as header("Content-type: text/html");
The problem with internet explorer is when you write xhtml1.1 and serve it as "Content-type: application/xhtml+xml" with a proper xhtml header that IE bites the bullet and refuses to parse it. So there is no problem sending IE xhtml1.1 with
Code:
<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
and without an xhtml header as it just treats it as text/html but your code is up to date and ready for when IE implements xhtml support (all it will do is throw IE into quirks mode). They tried to cram it in for the release of IE7 but failed due to time constraints but from the IE developer blog they state that xhtml support WILL be in IE8, so there is no reason not to adopt xhtml1.1.
What I do is send the above xml prolog and dtd and use php to check what the browser supports and if it does not support application/xhtml+xml I just send it a "Content-type: text/html" header. The code will work in IE and browsers that dont support application/xml+xhtml and I send header("Content-type: application/xhtml+xml"); to browsers that do support it (firefox, safari, konqueror, opera) and all is hunky dory.
If you are using php then here is some php I pulled from my framework and rewritten as basic php functions that determine what the browser supports and sets a proper mimetype to output headers with.
save this as header.php
Code:
function set_mimetype()
{
$mimetype = 'text/html';
if(isset($_SERVER['HTTP_ACCEPT']) && stristr($_SERVER['HTTP_ACCEPT'], 'application/xhtml+xml'))
{
/*
* The browser can handle application/xhtml+xml
* We now check Q values to see what the browser actually prefers, html or xhtml.
* if there's a Q value for application/xhtml+xml then also retrieve the Q value for text/html
*/
if(preg_match('/application\/xhtml\+xml;q=0(\.[1-9]+)/i', $_SERVER['HTTP_ACCEPT'], $matches))
{
$xhtml_q = $matches[1];
if(preg_match('/text\/html;q=0(\.[1-9]+)/i', $_SERVER['HTTP_ACCEPT'], $matches))
{
$html_q = $matches[1];
/*
* if the Q value for XHTML is greater than or equal to that for HTML
* then use the "application/xhtml+xml" mimetype
*/
if($xhtml_q >= $html_q)
{
$mimetype = 'application/xhtml+xml';
}
}
}
else // if there was no Q value, then just use the application/xhtml+xml mimetype
{
$mimetype = 'application/xhtml+xml';
}
}
/*
* The w3c validator does not send $_SERVER["HTTP_ACCEPT"] when requesting a document
* but we know it can handle application/xhtml+xml so set the mimetype as that.
*/
if (isset($_SERVER['HTTP_USER_AGENT']) && stristr($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator'))
{
$mimetype = 'application/xhtml+xml';
}
return($mimetype);
}
function output_headers()
{
// Cache-Control for HTTP/1.1, Pragma for older HTTP/1.0
header ('Content-type: ' . set_mimetype() . '; charset='iso-8859-1');
header ('Cache-Control: no-store, no-cache, must-revalidate');
header ('Pragma: no-cache');
header ('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header ('Expires: ' . gmdate('D, d M Y H:i:s', (time()-360000)) . ' GMT');
}
then at the top of your php pages
Code:
include('header.php');
output_headers();
if you use the firefox webdeveloper extension you can then go to "information > View Page Information" and you will see the type set as application/xhtml+xml rather than text/html or text/plain.
xhtml support is in most major browsers and once you get to grips with it you will be outputting leaner/cleaner code. If you use the code above you may want to edit the headers if you want to cache pages etc.