【问题标题】:Javascript image not loading in ChromeJavascript图像未在Chrome中加载
【发布时间】:2020-11-03 22:10:59
【问题描述】:

我正在做以下事情:

<!DOCTYPE html>
<html>

  <head>
    <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, minimum-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">


    <script>
      function LoadImage() {
        var rowCover = document.createElement("img");
        var ImgSRC = "https://marell-av.nl/thumbnails/A/A.jpg"

        rowCover.setAttribute("src", ImgSRC);
        rowCover.setAttribute("style", "margin-left: 5px; margin-right:10px; margin-top: 5px; height:200px; width:200px; float:left");
        //target.appendChild(rowCover);
        document.getElementById('tracks').appendChild(rowCover);
      }
    </script>
  </head>

  <body>


    <div id="tracks"></div>

    <script>
      LoadImage()
    </script>
  </body>
</html>

问题是该图像在 Firefox 中可以正常加载,但不能在 chrome 或 Edge 中加载。为什么? 当我检查 Chrome 中的代码时,链接很好。当我将链接“https://marell-av.nl/thumbnails/A/A.jpg”粘贴到新标签中时,图像加载正常。

作为旁注,我还想知道如何在加载失败的情况下加载占位符图像。

【问题讨论】:

  • 建议..与其在运行时创建元素,不如在html中创建并隐藏它,除非加载失败
  • ImgSRC 定义为imgSRC。为什么不发布也显示附加部分的实际代码?要检查加载是否失败,您有事件 onerror
  • 当您尝试使用this method 时会发生什么?
  • https://marell-av.nl 和这段代码是同一个站点吗?如果是这样,您可能不需要其中的完整 URL。如果没有,它会在您粘贴链接时要求登录。

标签: javascript html image google-chrome


【解决方案1】:

问题在于服务器人员。不知何故将图像移动到另一个文件夹就可以了。问题仍然存在,但为什么 firefox 完全没有问题,而不是 chrome。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-20
    • 2016-01-17
    • 1970-01-01
    相关资源
    最近更新 更多