如何获取IE 7打开XHTML文件? [英] How do I get IE 7 to open XHTML files?

查看:120
本文介绍了如何获取IE 7打开XHTML文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建的应用程序正在生成XHTML文档,这些文档将以多种不同的方式分发,包括电子邮件.我可以在Firefox或Chrome浏览器中打开这些文档(打开"是指从Windows资源管理器打开,而不是通过Web服务器打开).但是,使用IE 7,我遇到了两个(可能是三个)不同的问题.

An application I'm building is generating XHTML documents that are going to be distributed in a bunch of different ways, including email. I can open these documents in Firefox or Chrome (and by "open" I mean from Windows Explorer, not through a web server). With IE 7, though, I'm having two - possibly three - different problems.

如果文件以扩展名".xhtml"命名,则IE启动并关闭.有时它仍在任务管理器中运行,我必须将其杀死.有时不是.

If the files are named with the extension ".xhtml", then IE launches and then closes. Sometimes it's still running in Task Manager and I have to kill it. Sometimes not.

如果我用扩展名".htm"或".html"命名它们,则它们将正确打开,但出现IE信息栏时会告诉我它已阻止某种内容.这些文档不包含任何脚本,iframe或对象,它们就像普通的XHTML一样.他们甚至没有引用外部CSS.

If I name them with the extension ".htm" or ".html", then they open properly, except the IE Information Bar comes up telling me that it has blocked content of some kind. These documents don't contain any scripts or iframes or objects - they're as plain-vanilla XHTML as can be. They don't even reference external CSS.

当我为之开发的客户在他的环境中打开文档时(此时他只是使用".xhtml"扩展名),IE会打开它们并将其呈现为XML文档.

When the customer I'm developing this for opens the documents in his environment (he's just using the ".xhtml" extension at this point), IE opens them and renders them as XML documents.

我在Google上花费了相当多的时间来尝试深入研究,而我发现的所有事情都与在HTTP标头中指定MIME类型有关,这对我来说并不是特别有用.我实际上并没有提供这些文件.

I've spent a fair amount of time on Google to try and get to the bottom of this, and everything I find there has to do with specifying the MIME type in the HTTP header, which is not especially useful as I'm not actually serving these files.

所有文件(似乎)都具有正确的DOCTYPE,处理指令和名称空间声明;每个页面的顶部看起来像这样:

The files all (seem to) have the proper DOCTYPE, processing instruction, and namespace declarations; the top of each looks like 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">

有什么想法吗?

推荐答案

那么,有趣的故事. IE7实际上并不支持严格的XHTML .

So, funny story. IE7 doesn't actually support strict XHTML.

具体来说,如果您将其内容类型为application/xhtml+xml的XHTML提供给它,它将变成哦,那些新奇的XHTML东西,我对此一无所知",并将其视为XML文档.另一方面,如果为它提供内容类型为text/html的XHTML,它就会说:该HTML听起来有点可笑,但我可以阻止它."

Specifically, if you serve it XHTML with a content-type of application/xhtml+xml, it will go "oh, that new-fangled XHTML stuff, I don't know anything about it," and will treat it as an XML document. If, on the other hand, you serve it XHTML with a content-type of text/html, it goes, "this HTML tastes kinda funny, but I can choke it down."

有一个引人注目的骇客-由W3C建议,不少 -使IE呈现它认为的XML内容为HTML.基本上,您将仅IE的xsl:stylesheet处理指令添加到文档中,并引用具有HTML输出类型的XSLT身份转换.其他浏览器则忽略它. IE将其认为是XML文档的内容转换为自身的内容,然后将其呈现为HTML.我不知道该骇客会给您留下深刻的印象或震惊.

There's a remarkable hack - suggested by the W3C, no less - to make IE render what it thinks is XML content as HTML. You basically add the IE-only xsl:stylesheet processing instruction to the document and reference an XSLT identity transform with an output type of HTML. Other browsers ignore it; IE transforms what it thinks is an XML document (to itself) and then renders it as HTML. I don't know whether to be impressed or appalled by this hack.

但是,只有在文档可以解析对转换的引用时,该hack才起作用.谁打开了这些文档所附的电子邮件,则不一定能做到这一点.我想有一种在XML本身中包含转换的方法,但是我已经在它上面花了太多时间.如果我能找到正确的答案,我会花更多的时间,但这只会使我领会到错误答案的另一种味道.

But that hack only works when the document can resolve the reference to the transform. Whoever opens the email that these documents are attached to won't necessarily be able to do this. I suppose there's a way of including the transform inside the XML itself, but I have already spent Way Too Much Time on this. I'd spend more time if it got me to the right answer, but this just gets me to a different flavor of wrong answer.

所以我要做愚蠢的事情,并用.htm扩展名命名文件.注册表设置将文件扩展名映射到内容类型.因此,.htm扩展名是text/html ,. xhtml扩展名是application/xhtml+xml. IE以及使用注册表确定内容类型的所有其他内容,会将这些文档视为text/html,它们将呈现,并且整个过程或多或少会起作用.但是我对此不满意.

So I'm going to do the stupid thing, and name the files with an .htm extension. Registry settings map file extensions to content types. So the .htm extension means text/html, and the .xhtml extension means application/xhtml+xml. IE, and everything else that uses the registry to determine the content type, will treat these documents as text/html, and they'll render, and the whole thing will more or less work. But I'm not happy about it.

这篇关于如何获取IE 7打开XHTML文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆