在本地主机上访问时,SVG无法正常工作.为什么? [英] SVG not working when access on localhost. Why?

查看:357
本文介绍了在本地主机上访问时,SVG无法正常工作.为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道为什么此页面 http://emacsformacosx.com/上的相同代码为何在以下情况下无法呈现托管在本地tomcat服务器上?

Does anybody know why the same code from this page http://emacsformacosx.com/ would not render when hosted on a local tomcat server?

我正在尝试使用某些SVG,但看不到使其在本地工作.有什么想法吗?

I am trying to play with some SVG but can't see to make it work locally. Any ideas?

推荐答案

该页面为XHTML,因此应为其提供适当的Content-Type标头.如果该页面以text/html格式提供,那么Firefox和Chrome(我已签入的仅有两个)将无法识别SVG正常运行所必需的XML名称空间.

The page is XHTML, so it should be served with an appropriate Content-Type header. If the page is served as text/html, then Firefox and Chrome (the only two I've checked in) won't recognise the XML namespaces necessary for the SVG to work.

尽管实时页面带有页眉

Content-Type: text/xml; charset=UTF-8

严格来讲,这是不正确的.在我的测试中,

this is not, strictly speaking, correct. In my tests, serving it with

Content-Type: application/xhtml+xml; charset=UTF-8

使它能够正确呈现,并且是XHTML的适当类型.

causes it to render correctly, and is the appropriate type for XHTML.

请注意,您必须在服务器上检测Internet Explorer(以及其他不了解XHTML的浏览器),然后将内容类型更改为text/html-如果显示为application/xhtml+xml内容类型,则IE会提示用户下载文件;对于text/xml,它将显示打印精美的XML文档树(尽管有时会感到困惑,并通过内容嗅探设法正确显示HTML).

Note that you'll have to detect Internet Explorer (and other browsers that don't understand XHTML) on the server and change the content type to text/html - if presented with the application/xhtml+xml content type IE will prompt the user to download the file; for text/xml it will show the pretty-printed XML document tree (although occasionally it will get confused and manage to display the HTML correctly through content sniffing).

正如codedread所说,如果要提供原始SVG文件,则需要使用SVG内容类型,但是在这种情况下,该文件实际上是XHTML,并且在单独的命名空间中具有内联SVG,因此XHTML类型是正确的.

as codedread says, if you want to serve raw SVG files you'll need to use the SVG content type, but in this case the file is in fact XHTML with inline SVG in a separate namespace, so the XHTML type is correct.

这篇关于在本地主机上访问时,SVG无法正常工作.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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