【发布时间】:2011-12-01 02:07:45
【问题描述】:
我有一些类似于下面的代码,在我的网站上显示了一个 svg 图像。
<a href="http://site.com/path/to/file.svg">
<img src="http://site.com/path/to/file.svg">
</a>
svg 文件如下所示:
<svg width="600" height="400" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g>
<title>Annotation</title>
<image xlink:href="http://site.com/path/to/image.jpg" id="svg_1" height="400" width="600" y="0" x="0"/>
</g>
<g>
<title>Layer 1</title>
<g id="svg_2"/>
<path fill="none" stroke="#000000" stroke-width="3" id="svg_3".....
<line id="svg_4" y2="249" x2="134" y1="248" x1="155" stroke-width="3" stroke="#000000" fill="none"/>
<path d="m97,177c0,-1 -0.292892,-1.292892 -1,-2c-0.707108,-0.707108......
</g>
</svg>
正在加载 svg(通过带有正确标题的 php 等)并且可以看到 svg 中的线条和对象,但看不到图像。
如果我右键单击并在新窗口中打开链接,我可以看到背景图像。如果我然后切换回 svg 链接在 html 中显示图像的第一个选项卡。
浏览器似乎没有加载图像,所以我尝试了各种方法,比如在它旁边加载<img src="http://site.com/path/to/image.jpg"/>。普通图像有效,但 svg 中的图像仍然无法显示。
最好避免像 iframe 这样的事情,因为在 img 标签上设置大小并且整个 svg 缩放是好的(除非你可以在 iframe 中这样做?)
任何指针将不胜感激。
TL;DR
svg 中的图像只有在没有 html 的情况下在第二个选项卡中打开时才会显示
【问题讨论】:
标签: javascript html svg