IE8 不显示图像(红色 x)...有时

发布于 2024-10-02 18:32:47 字数 2805 浏览 0 评论 0原文

我对以下任何其他浏览器(Chrome、Firefox)上都不会发生的问题感到抓狂:

  • IE8 缓存被清除,
  • 浏览器启动时会打开 HTML/Javascript 页面,该页面会动态请求并创建一些图像。此 HTML 页面由 Tomcat 服务器 localhost:8084 提供。
  • 大多数情况下,请求的 10 个图像中 IE 显示为 RED X。
  • 开发人员图像报告 (F12) 将某些图像“文件大小”显示为正确的 # 字节,但图像仍然不显示,或者某些图像文件大小“未知字节” “并且图像不起作用。
  • 有时 10 个图像中有 2-4 个显示出来,而其余的则失败!
  • 有时,在疯狂点击刷新 10 亿次后,图像就会出现。
  • 真正的问题是,当我在 HTTP 服务器中设置断点时,套接字甚至没有打开。 IE 在失败之前甚至没有尝试从服务器获取图像。
  • 最后,如果我运行相同的代码但从谷歌地图之类的地方请求图像,它可以在 IE 中正常工作。

这是我的 javascript 代码:

<script type="text/javascript">
    var ctr = 0;
    function getImage(url)
    {
        var img = document.createElement("img");
        img.src = url + "&nc=" + ctr;
        ctr ++;
        img.width = 128;
        img.height = 128;
        document.body.appendChild(img);
    }

    for (var i = 0; i < 10; i=i+1)
    {
        //THIS FAILS MOST OF THE TIME
        setTimeout("getImage('http://myHostName:9980/GenerateImageStatic?parameter=1')", 1000);
        //THIS WORKS! WHY?
        //setTimeout("getImage('http://maps.google.com:80/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=14&size=512x512&maptype=roadmap&markers=color:blue|label:S|40.702147,-74.015794&markers=color:green|label:G|40.711614,-74.012318&markers=color:red|color:red|label:C|40.718217,-73.998284&sensor=false')", 1000);
    }
</script>

对于 HTTP 服务器,我使用 BOOST 示例 ASIO HTTP 服务器 链接 我修改了它,因此对于任何 URI 请求,它都会发送一个 png 文件(我尝试了各种文件以确保它不是不好的 PNG 编码)。 HTTP 标头的内容类型为:“image/png”。因此发送了正确的 mime 类型。

我很长时间以来一直在努力寻找解决方案。阅读各种帖子:

  • Mime类型是问题。 Mime 类型对我来说不是问题。我设置了内容类型。我还使用 Firefox LiveHTTPHeader 插件来查看从服务器发送的标头。除了一些缓存控制标头之外,我的标头在内容类型方面与谷歌发送的标头相同:
  • 安全错误。好吧,也许跨域图像存在安全风险。或者有什么东西阻止了请求。那么为什么它不会 100% 失败呢?!为什么IE不请求跨域图片?然而,maps.google.com 请求有效,而我的请求仅有时有效。这同样适用于任何防火墙或防病毒软件。我还尝试在各种端口(80、8080、9980)上运行服务器。
  • Javascript 错误。我认为Javascript是正确的。事实上,我在使用 GWT 时也遇到了同样的问题。所以我认为问题出在 GWT 上。 IE 和 GWT 存在与图像相关的事件错误。所以我将代码简化为 Javascript。没有 GWT。
  • 也许这是 C++ HTTP Server 实现。这是一种可能性。然而 Firefox 和 Chrome 使用相同的代码没有问题。

有什么想法吗? 谢谢。

编辑 我将 myHostName 添加到受信任的站点。我还将内部和互联网站点的安全设置降低到低水平。如果启用的话,我将尝试禁用服务器上的保活。然而,正如我提到的,我根本没有看到 IE 尝试获取图像。套接字不会收到来自 IE 的任何请求,因此从标头中删除 keep-alive 可能没有帮助。

I'm going mad with the following problem which does not happen on any other browser (Chrome, Firefox):

  • IE8 cache is cleared
  • browser starts opens HTML/Javascript page that requests and creates a few images dynamically. This HTML page is served from a Tomcat server localhost:8084.
  • Most of the time out of 10 images that are requested IE displays RED X.
  • Developer Image Report (F12) shows some images "file size" as correct # bytes, yet the image is still not displayed, or some images file size "unknown bytes" and image doesn't work.
  • Sometimes 2-4 out of 10 images show up and the rest fail!
  • Sometimes in a mad fury of hitting refresh 1 billion times, the images show up.
  • The real kicker is that when I put a break point in my HTTP Server, the socket isn't even opened. IE isn't even attempting to fetch the images from the server before failing.
  • And finally if I run the same code but request an image from somewhere like google maps, it works in IE without problems.

Here's my javascript code:

<script type="text/javascript">
    var ctr = 0;
    function getImage(url)
    {
        var img = document.createElement("img");
        img.src = url + "&nc=" + ctr;
        ctr ++;
        img.width = 128;
        img.height = 128;
        document.body.appendChild(img);
    }

    for (var i = 0; i < 10; i=i+1)
    {
        //THIS FAILS MOST OF THE TIME
        setTimeout("getImage('http://myHostName:9980/GenerateImageStatic?parameter=1')", 1000);
        //THIS WORKS! WHY?
        //setTimeout("getImage('http://maps.google.com:80/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=14&size=512x512&maptype=roadmap&markers=color:blue|label:S|40.702147,-74.015794&markers=color:green|label:G|40.711614,-74.012318&markers=color:red|color:red|label:C|40.718217,-73.998284&sensor=false')", 1000);
    }
</script>

For HTTP Server I'm using BOOST sample ASIO HTTP Server Link I modified it so for any URI request, it sends a png file (I've tried various files to make sure it's not PNG encoding that's bad). The HTTP header has Content-type: "image/png". So correct mime type is sent.

I've been trying to find a solution for a long time. Read through various posts:

  • Mime type is the problem. Mime type is not the problem in my case. I set the Content-type. I've also used Firefox LiveHTTPHeader plugin to view the headers sent from the server. Except for some cache control headers, my headers are same as what google sends in terms of Content-type:
  • Security error. Ok maybe the cross domain images are a security risk. Or something is blocking the request. Well then why doesn't it fail 100% of the time?! Why does IE not request any cross domain images? Yet maps.google.com request works, and mine only works sometimes. Same applies to any firewall or anti-virus. I've also tried running the server on various ports (80, 8080, 9980).
  • Javascript error. I think the Javascript is correct. I was actually getting the same problem with GWT. So I thought it was GWT that was the problem. And there was an event bug with IE and GWT related to images. So I simplified the code to just Javascript. no GWT.
  • Maybe it's the C++ HTTP Server implementation. It's a possibility. However Firefox and chrome work with the same code without problems.

Any ideas?
Thanks.

EDIT
I added myHostName to trusted sites. I also lowered the security settings to low for internal and internet sites. I'm going to try to disable keepalive on the server if enabled. However as I mentioned I don't see IE making an attempt to fetch the image at all. The socket doesn't receive any requests from IE, so removing keep-alive from headers may not help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

乄_柒ぐ汐 2024-10-09 18:32:47

检查您的图像采用的颜色模式。

我不小心在 Photoshop 中将图像的颜色模式从 RGB8 切换为 CMYK,并遇到了同样的问题。 IE8 会无法显示图像,而 Firefox 则完全没有问题。

Check what color mode your images are in.

I have accidentally switched the color mode of an image from RGB8 to CMYK in Photoshop, and ran into the same problem. IE8 would fail to display the image, while Firefox would have no trouble at all.

在巴黎塔顶看东京樱花 2024-10-09 18:32:47

我相信在 IE 中,您需要在将元素附加到 DOM 后设置源,否则它将无法正确渲染。

I believe that in IE you need to set the source after the element is appended to the DOM, otherwise it won't render correctly.

宛菡 2024-10-09 18:32:47

听起来像是你的服务器有问题。可以尝试一些方法来缩小问题范围:

看看它是否静态工作。即制作一个包含这些图像的平面 html 页面。他们出现了吗?

尝试更改它,以便您的计时器执行执行循环的单个函数,而不是在循环中调用计时器。

让它做一个 document.write (在页面加载时,没有任何计时器),只需编写元素的 html(以及 url,以便您可以看到它在做什么)

让它这样做,而不是使用计时器,单击页面上的按钮的响应。让它一次处理一张图像。

我认为如果您尝试所有这些方法,您可能会解决问题,但如果没有,请报告发生的情况。

It sounds like an issue with your server. A few things to try, to narrow down the problem:

See if it works statically. That is make a flat html page that includes these images. Do they show up?

Try changing it so that your timer executes a single function that does a loop, rather than calling the timer in a loop.

Have it do a document.write (at page load, without any timers), simply writing the html for the elements (along with the urls so you can see what it is doing)

Have it do it, rather than with a timer, in response to clicking a button on the page. Have it do one image at a time.

I think if you try all these things, you'll likely arrive at the problem, but if not, report back what happens.

机场等船 2024-10-09 18:32:47

我有同样的问题,图像在 IE8 中不显示,但在其他浏览器中正常。即使本地保存的文件也是如此。如果我用 IE8 打开,我会得到红色 x,但其他所有程序都显示正常。我查看了图像的属性,它们源自 Photoshop,所以我猜测这是如上所述的 CMYK 问题。如果我使用 RGB 项目保存此图像,问题就解决了。

I have the same problem with images not displaying in IE8 but ok in other browsers. This is even the case with locally saved files. If i open with IE8 I get red x, but every other program displays ok. I looked at the properties of the image and they originated from Photoshop, so I'm guessing it's the CMYK issue as stated above. If I save this image using RGB project, the issue is resolved.

最近可好 2024-10-09 18:32:47

是的,我还是不知道问题出在哪里。
人们一直建议它是 CMYK。如果该解决方案适合您,那就太好了。我始终使用 libPNG 进行编码和 RGB。 CMYK 对我来说不是问题。

我使用 Boost/asio http 服务器示例 #3 实现了 HTTP 服务器。以及 Java Servlet。同样的问题。有时它会起作用,有时它不会让

我放弃。

Yeah, I still don't know what the problem is.
People have been suggesting it's CMYK. If that solution works for you, that's great. I'm using libPNG for encoding and RGB at all times. CMYK was not the problem for me.

I implemented HTTP server using Boost/asio http server sample #3. As well as Java Servlet. Same problems. Sometimes it works, sometimes it doesn't

I give up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文