【发布时间】:2019-01-25 22:12:55
【问题描述】:
直截了当的问题。我目前正在调试一个问题,尽管能够在几乎任何其他浏览器上呈现,但它无法在 Edge 上正确呈现:
var img = new Image();
img.onload = function() {
console.log("succ");
}
img.onerror = function(error) {
console.log(error);
}
img.src = 'data:image/svg+xml;utf8,<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"><style>polygon { fill: black } div {color: white;font:18px serif;height: 100%;overflow: auto;}</style><polygon points="5,5 195,10 185,185 10,195" /><!-- Common use case: embed HTML text into SVG --><foreignObject x="20" y="20" width="160" height="160"><!--In the context of SVG embeded into HTML, the XHTML namespace couldbe avoided, but it is mandatory in the context of an SVG document--><div xmlns="http://www.w3.org/1999/xhtml">Lorem ipsum dolor sit amet, consectetur adipiscing elit.Sed mollis mollis mi ut ultricies. Nullam magna ipsum,porta vel dui convallis, rutrum imperdiet eros. Aliquamerat volutpat.</div></foreignObject></svg>'
document.getElementById("target").append(img);
<div id="target"></div>
当我进入代码时,Image 使用其src 属性实例化的方式显然存在错误。但是我无法进入浏览器代码来查看它为什么不起作用。有没有可能以某种方式做到这一点?
【问题讨论】:
-
您好,请在问题本身中包含您的 CodePen 中的代码,而不是为了在您的问题中发布没有任何代码的此类链接而规避规则。
-
已修复,我使用了内置的 codepen 功能
标签: javascript svg microsoft-edge data-uri