Forum Moderators: open

Message Too Old, No Replies

JS detection of page's mimetype? (without doc write)

         

JAB Creations

7:46 am on Dec 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Unfortunately I am unaware of how to check the mime types on some browsers (as I am now working on serving application/xhtml+xml for supported browsers). Is there a way I can use JS to tell me what the mimetype is that will work in most browsers (and also when the mimetype is application/xhtml+xml as in I cant use document.write)?

Span

10:43 am on Dec 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You would have to check the UA's HTTP_ACCEPT header to see if it is capable of handling application/xhtml/xml and if true, send the right mime-type. That can't be done with JS.

Partial example:


HTTP_ACCEPT: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
SERVER_SOFTWARE: Apache
HTTP_ACCEPT_CHARSET: ISO-8859-1,utf-8;q=0.7,*;q=0.7
HTTP_USER_AGENT: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8) Gecko/20051107 Camino/1.0b1
SERVER_PROTOCOL: HTTP/1.1

.htaccess example


RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml
RewriteCond %{HTTP_ACCEPT}!application/xhtml\+xml\s*;\s*q=0
RewriteCond %{REQUEST_FILENAME} \.html$
RewriteCond %{THE_REQUEST} HTTP/1\.1
RewriteRule .* - [T=application/xhtml+xml]

PHP


if (isset($_SERVER["HTTP_ACCEPT"]) && stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml")){
header("Content-type: application/xhtml+xml");
}
else {
header("Content-type: text/html");
}