【问题标题】:Is it possible to step through native code in the Edge (or any browser's) debugger?是否可以在 Edge(或任何浏览器的)调试器中单步执行本机代码?
【发布时间】: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);
&lt;div id="target"&gt;&lt;/div&gt;

当我进入代码时,Image 使用其src 属性实例化的方式显然存在错误。但是我无法进入浏览器代码来查看它为什么不起作用。有没有可能以某种方式做到这一点?

【问题讨论】:

  • 您好,请在问题本身中包含您的 CodePen 中的代码,而不是为了在您的问题中发布没有任何代码的此类链接而规避规则。
  • 已修复,我使用了内置的 codepen 功能

标签: javascript svg microsoft-edge data-uri


【解决方案1】:

在我这边测试了您的代码后,问题似乎与样式中的高度属性有关。

尝试从这部分代码中删除高度属性

div {颜色:白色;字体:18px 衬线; 高度:100%;溢出: 自动;}

然后,代码如下:

<div id="target"></div>

<script type="text/javascript">
    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;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>'
    img.style = "height :100%";
    document.getElementById("target").append(img);
</script>

结果like this

【讨论】:

  • 是的,我通过了。事实证明 edge 不喜欢百分号,它认为它没有正确转义。通过编码函数运行 URL 解决了我的问题。
猜你喜欢
  • 2013-07-03
  • 2020-11-06
  • 2011-04-13
  • 2020-09-03
  • 1970-01-01
  • 2012-01-17
相关资源
最近更新 更多