douwen8118 2011-05-24 21:52
浏览 157
已采纳

使用Safari显示SVG的Doctype问题

I have several SVG images I'd like to layout on a page. Firefox and Chrome have given me no issues whatsoever, but Safari only seem to display the SVG image if and only if the document has an ".xhtml" extension. If I try to use PHP code (and therefor a ".php" extension) the exact same markup I used in the ".xhtml" document will no longer display the SVG image. The problem is of course, I must use PHP for the project at hand. Any suggestions? Here's the source code:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:lang="de" xmlns:xml="http://www.w3.org/XML/1998/namespace">
<head>
<title>SVG Safari Test</title>
</head>
<body>
<!-- Generator: Adobe Illustrator 15.0.2, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="500px" height="500px" viewBox="0 0 500 500" enable-background="new 0 0 500 500" xml:space="preserve"><circle cx="250" cy="250" r="238.048"/></svg>
</body>
</html>
  • 写回答

2条回答 默认 最新

  • duan88014 2011-05-24 22:07
    关注

    The reason .xhtml works in Safari and .html doesn't is that Safari needs to treat the document as XML to allow embedded SVG. The latest versions of Firefox and Chrome use a HTML5 parser which allows SVG to be embedded in plain HTML documents, so they should work with both.

    To have it render properly in Safari you need to set the content type to application/xhtml+xml. Use this in your PHP file before you output any content:

    <?php
    header('Content-type: application/xhtml+xml');
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序