如下截图所示,iframe中的代码是相同的。
![screenshot](https://istack.dev59.com/Scgoe.webp)
<svg height="150" width="300">
<defs>
<linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" style="stop-color:rgb(255,255,0);stop-opacity:1" />
<stop offset="100%" style="stop-color:rgb(255,0,0);stop-opacity:1" />
</linearGradient>
</defs>
<ellipse cx="100" cy="70" rx="85" ry="55" fill="url(#grad1)" />
</svg>
<br><br>
<iframe width="300" height="150" srcdoc='<svg height="150" width="300">
<defs>
<linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" style="stop-color:rgb(255,255,0);stop-opacity:1" />
<stop offset="100%" style="stop-color:rgb(255,0,0);stop-opacity:1" />
</linearGradient>
</defs>
<ellipse cx="100" cy="70" rx="85" ry="55" fill="url(#grad1)" />
</svg>'></iframe>
看起来与linearGradients有关,或者与URL以及它们在这种情况下的行为有关。
我最近遇到了一些有关iframes和srcdocs的问题,并在SO上发布了这个问题,得到了很好的回答:iframes rendering mysteriously differently from regular web pages? 这对许多不一致性有所帮助,但似乎与这个问题无关。
我正在使用Chrome/Webkit。
#
字符也不会像在数据URI中一样破坏解析(回退颜色可以正常呈现)。 - AmeliaBR