Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果mime类型等于text/xml,则显示svg_Svg_Mime Types - Fatal编程技术网

如果mime类型等于text/xml,则显示svg

如果mime类型等于text/xml,则显示svg,svg,mime-types,Svg,Mime Types,我试图在我的主页上使用svg图像, 基本上使用以下代码: <html><head/><body> <img src="images/avatar.svg" width="135mm" height="210mm"/> </body></html> 在我的电脑上一切正常(Linux和apache服务器), 但是,在传输到非常有限的主机后,图像不再显示。 (注:使用Chrome29和Opera12测试) 原因:它是在“te

我试图在我的主页上使用svg图像, 基本上使用以下代码:

<html><head/><body>
<img src="images/avatar.svg" width="135mm" height="210mm"/>
</body></html>

在我的电脑上一切正常(Linux和apache服务器), 但是,在传输到非常有限的主机后,图像不再显示。 (注:使用Chrome29和Opera12测试)

原因:它是在“text/xml”下传输的,而不是在“image/svg+xml”下传输的

我要寻找的是一种在我的主页上显示这张图片的方法,最好不要丢失img标签

关于这一点,棘手的部分是:

  • 我无法访问魔法文件
  • 我不允许上传.htaccess
  • 我没有服务器端脚本
  • 我不想使用(I)帧
  • 基本上我只能添加(x)html、css和javascript
要缓解一些限制,请执行以下操作:

  • 它不需要在IE下工作
编辑: 他们已经联系了技术支持,声称他们的主机正常工作。因此,这就是我寻找解决方案的原因(目前正在使用.png,但对此并不满意)

您可以使用数据URI(您可以自己指定内容类型),也可以使用HTML5,它允许内联SVG(这需要您删除img标记)

:


红圈
" />
(甚至验证)

管理者设法帮助我解决这个问题

我不是直接将图像嵌入HTML,而是使用一些javascript检索图像:

<script type="text/javascript">
     function getSVG(source)
     {
             xmlhttp = new XMLHttpRequest();
             xmlhttp.open("GET", source, false);
             xmlhttp.send();
             return "data:image/svg+xml," + xmlhttp.responseText;
     }
</script>
<img src="images/avatar.svg"
     onerror="this.onerror = null;
              this.src = getSVG('images/avatar.svg')"/>

函数getSVG(源代码)
{
xmlhttp=新的XMLHttpRequest();
open(“GET”,source,false);
xmlhttp.send();
返回“data:image/svg+xml,”+xmlhttp.responseText;
}

服务器工作正常!

我会说:联系支持人员。这是一个明显的错误配置,至少如果这确实是您上传的svg文件……我建议不要使用物理单位。如果有人用手机查看您的站点会发生什么情况?图像将比屏幕大。我建议使用
rem
单位。
image/svg+xml
是svg的官方注册mediatype(请参见IANA),它并不完全是新的(apache已随svg mimetype随默认值一起提供多年了)。+1用于联系托管公司。这是一个好主意,结合了类似onerror=“this.onerror=null;this.src='images/avatar.png'”甚至可以只使用图像文件本身(无需在html中硬编码图像)。只需查看该部分是否工作,但是如果需要,javascript可以将其删除。tnxi如果要使用javascript,可以从XHR对象获取arraybuffer(如果您相应地设置了
responseType
)并使用blob,并且当前正在使用此blob:
函数getSVG(source){xmlhttp=new XMLHttpRequest();xmlhttp.open(“GET”,source,false);xmlhttp.send();return“data:image/svg+xml,“+xmlhttp.responseText;}
并且它可以按照需要工作。再次使用.Tnx
<script type="text/javascript">
     function getSVG(source)
     {
             xmlhttp = new XMLHttpRequest();
             xmlhttp.open("GET", source, false);
             xmlhttp.send();
             return "data:image/svg+xml," + xmlhttp.responseText;
     }
</script>
<img src="images/avatar.svg"
     onerror="this.onerror = null;
              this.src = getSVG('images/avatar.svg')"/>