简体   繁体   中英

Open HTML as XHTML

Having an .html file is it possible to force the browser to treat the contents as XHTML ? I mean the file opened from both local or web location. Maybe some on-the-fly convertion or something like that?

The background:

Firefox and Opera supports natively MathML when the code is embedded in a XHTML file. I need to get a .html file with MathML that would be supported by the mentioned browsers properly.

Thank you for any support.

For local files (see below if you are using a server):

Browsers generally only run off file extensions for determining if a local file is HTML or XHTML.

Your options:

  • Rename the files
  • Run a local webserver that can serve with an application/xhtml+xml content type
  • Wait for HTML 5 support of inline SVG
  • Use JS to generate the SVG
  • Use symbolic links (if you are on *NIX) so you have both file names available
  • Add a Doctype detection and parse mode switching feature to Firefox, it is open source (yes, I realize this isn't the most practical suggestion, that is why it is last)

For files served via HTTP:

Consult the manual to find out how to change the content type for a given file extension. For example, Apache can use the AddType directive .

File extension has nothing to do in this case. The only thing that really matters is the Content-Type header. By default your webserver treat .html files, as text/html , but you should force it to send is as application/xhtml+xml .

If you're using any server-side language, you can do something like that (PHP example)

header('Content-Type: application/xhtml+xml');

If you're unable to use any programming language, then you can configure your webserver to treat .html files as XHTML (Apache, .htaccess example)

AddType application/xhtml+xml .html

Edit:

I didn't noticed that you're also trying to open XHTML from local file. Then file extension may be important - but David Dorward answer to that case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM