Windows 7 小工具无法重新加载图像
我是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用唯一的 URL 破坏缓存:
Break the cache by using a unique URL: