Windows 7 小工具无法重新加载图像

发布于 2024-12-22 16:38:58 字数 999 浏览 1 评论 0原文

我是 Windows 小工具的新手,需要一些帮助。我想做一个显示的小工具 来自网络的一些信息(游戏服务器状态)。我已经使用 PHP 实现了这一点,但我们知道 gadgets 不支持 PHP。我用谷歌搜索,但没有在 JavaScript 中找到任何类似于“fsockopen”的内容。所以我决定从状态制作图片并将其保存为PNG。 小工具已成功加载它,但当我尝试更新图像时,它不会改变。 每次我更改图片并使用“localhost/610status.png”网址时,它都会从某种缓存中打开一些旧图片。相同的代码在 Firefox 中完美运行。

以下是我的小工具代码的必要部分:

<script type="text/javascript" language="javascript">
      //var a=0;
      function init()
      {
            //document.getElementById("status").src="images/1.png";
            document.getElementById("status").src="http://localhost/610status.png";
            //document.getElementById("gadgetContent").innerHTML = a;
            //a+=1; //for testing timeout
            setTimeout("init()", 6000);
      }
</script>
</head>
<body onload="init();">
      <img id="status" src="images/1.png"  />
</body>

正如您从评论中看到的那样,我测试了超时和加载功能是否有效。也许有更简单的方法可以做到这一点,但我不太熟悉所有这些 JavaScript 和 Windows 小工具的可能性。解决这个问题的方法是强制小工具重新加载图像,但如何做到这一点呢?

I'm new with Windows gadgets and I need some help. I want to make gadget which show
some information from network (game server status). I already achieved this with PHP, but we know gadgets does not support PHP. I googled but didn't find anything similar to "fsockopen" in JavaScript. So I decided to make picture from status and saved it to PNG.
Gadget loaded it successfully but when I'm trying to update image it wont change.
Every time I change picture and use "localhost/610status.png" url it open some old picture from some kind of cache. Same code works perfectly with firefox.

Here are necessary parts of my gadget code:

<script type="text/javascript" language="javascript">
      //var a=0;
      function init()
      {
            //document.getElementById("status").src="images/1.png";
            document.getElementById("status").src="http://localhost/610status.png";
            //document.getElementById("gadgetContent").innerHTML = a;
            //a+=1; //for testing timeout
            setTimeout("init()", 6000);
      }
</script>
</head>
<body onload="init();">
      <img id="status" src="images/1.png"  />
</body>

As you see from comments I tested for sure that timeout and onload things will work. Maybe there are easier ways to do this, but I'm not very familiar all those JavaScript and Windows gadgets possibilites. What would fix this is to force gadget to reload image, but how to do it?

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

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

发布评论

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

评论(1

爱的十字路口 2024-12-29 16:38:58

使用唯一的 URL 破坏缓存:

"http://localhost/610status.png?now=" + new Date()

Break the cache by using a unique URL:

"http://localhost/610status.png?now=" + new Date()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文