定期刷新页面上的图像
我正在构建一个页面来显示一堆网络摄像头图像并定期更新它们,以便该页面可以用于一目了然的监控。但是,我在定期重新加载工作方面遇到问题。我的代码看起来像这样:
<div class='cameras'>
<div class='camera'>
<h4>Desk</h4>
<img height='240' src='http://somehost/cameras/cam0/lastsnap.jpg' width='320'>
</div>
<div class='camera'>
<h4>Main Room</h4>
<img height='240' src='http://somehost/cameras/cam1/lastsnap.jpg' width='320'>
</div>
<div class='camera'>
<h4>Studio</h4>
<img height='240' src='http://somehost/cameras/cam2/lastsnap.jpg' width='320'>
</div>
</div>
理想情况下,我希望这些东西每几秒钟从其指定的 URL 重新加载一次,而不必为每个摄像头生成单独的 JS。我已经将 jQuery 用于其他一些零散的部分,所以坚持下去会很棒 - 再说一次,一个简单的 JS 解决方案也很好。
StackOverflow JS 大神们,有什么想法吗?
I'm building a page to display a bunch of webcam images and update them periodically so that the page can be used for at-a-glance monitoring. However, I'm having issues getting the periodic reload working. My code looks something like:
<div class='cameras'>
<div class='camera'>
<h4>Desk</h4>
<img height='240' src='http://somehost/cameras/cam0/lastsnap.jpg' width='320'>
</div>
<div class='camera'>
<h4>Main Room</h4>
<img height='240' src='http://somehost/cameras/cam1/lastsnap.jpg' width='320'>
</div>
<div class='camera'>
<h4>Studio</h4>
<img height='240' src='http://somehost/cameras/cam2/lastsnap.jpg' width='320'>
</div>
</div>
Ideally I'd like to get these things reloading every couple of seconds from their specified URLs without having to generate individual JS for each camera. I've got jQuery in use for a few other bits and pieces, so sticking to that would be great - then again, a plain JS solution is fine too.
Any ideas, StackOverflow JS Gods?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
好的,解决了这个问题:
将获取“相机”类中的所有 img 元素,并通过添加到 URL 的随机数进行缓存清除,每秒刷新它们,每次重新加载时都会更改该随机数,而不会使用正则表达式使 URL 过长替换现有号码。
Okay, solved this:
Will take all img elements in a "camera" class, and refresh them every second with cache-busting via a random number added to the URL, which is changed every reload without making the URL obscenely long using a regexp to replace the existing number.
尝试在页面上重写元标记,因为
它与文本配合使用很酷。用图像结账
Try rewriting meta tag on you page as
It works cool with the text.Checkout with images
为图像生成图像源[定期]
在此处测试
< strong>PS:该技术不需要重新加载整个页面
Generate image sources to the images [for regular intervals of time]
Test it here
PS :this technique doesn't require the reloading of entire page
如果您想在指定的时间内刷新页面,您可以在 html 中执行此操作,也可以
将此标记添加到页面头标记,
此处内容是以秒为单位的持续时间
请参阅此
http://webdesign.about.com/od/metataglibraries/a/aa080300a .htm
If you want to refresh the page in a specified duration you can do that in html also
Add this tag to your page head tag
here content is the duration in seconds
Refer this
http://webdesign.about.com/od/metataglibraries/a/aa080300a.htm