PDA

View Full Version : Xhtml


steve_d555
September 5th, 2005, 12:50 AM
As you all should know, XHTML should be sent as application/xhtml+xml
Sadly, Internet Explorer is not smart enough to be able to parse it and insteads starts downloading as a file. There is a way around this, by changing Content-Types you will still be able to validate as proper XHTML (1.1 in my case), but allow IE users to see your website.

Just put the following in your controller and call it whenever needed. There is a special case for the W3C Validator as it does not send out that it accepts application/xhtml+xml.

def set_header()
http_accept = @request.env["HTTP_ACCEPT"]
if @request.env["HTTP_USER_AGENT"].scan("W3C_Validator") != nil
@headers ["Content-Type"] = "application/xhtml+xml"
else
if http_accept.scan("application/xhtml+xml") != nil
@headers["Content-Type"] = "application/xhtml+xml"
elsif http_accept.scan("application/xml") != nil
@headers["Content-Type"] = "application/xml"
elsif http_accept.scan("text/xml") != nil
@headers["Content-Type"] = "text/xml"
else
@headers["Content-Type"] = "text/html"
end
end
end


Hope this helps some people.

rob
September 5th, 2005, 12:39 PM
Thanks for that info. Ya know, it seems we're spending more and more time these days getting around IE's flaws :(

burntout
September 17th, 2005, 08:23 PM
def set_header()
@headers["Content-Type"] =
if @request.env["HTTP_USER_AGENT"] =~ /W3C_Validator/
"application/xhtml+xml"
else
case @request.env["HTTP_ACCEPT"]
when /application\/xhtml\+xml/, /application\/xml/, /text\/xml/: $&
else "text/html"
end
end
end


Phew, that's easier on my eyes ;)

steve_d555
September 17th, 2005, 11:33 PM
Heh, actually I was just about to rewrite it also, I finally booted into Windows to try my site under IE and ..... I guess it doesn't work that well :p

Thanks.