html刷新图片

文章目录


前言

海思3516的一个开发板,不断的采集图像编码为jpeg,保存为同一个文件。打算用网页实现查看视频的效果,需要前端能够自动刷新。

目前找到了两个方法,一个是网页的不断刷新,一个是页面内图像元素的不断刷新。

网页整体刷新

使用meta标签让浏览器不断刷新界面,和手动点刷新效果一样。

html 复制代码
<meta http-equiv="refresh" content="1">
html 复制代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="refresh" content="1">
<title>test</title>
</head>
<body>
    <img id="pic" src="snap_chn1.jpg" />
</body>
</html>

改变图像的url

使用setInterval不断改变图像的地址,这里加了个时间确保浏览器会去刷新,不加的话好像不变。

可以用浏览器去调试看url是不是自己想要的,有没有设置对。

c 复制代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>test</title>
</head>
<body>
    <img id="pic" src="snap_chn1.jpg" />

    <script>
        setInterval(function(){
            var tmpImage = new Image();
            tmpImage.src = "snap_chn1.jpg"+"?t="+Math.random();
            document.getElementById("pic").src = tmpImage.src;

        }, 1000);
    </script>
</body>
</html>

备注

上面方法都可以刷新图像,但是实际使用的效果有些不理想,图像很多时候刷不出来,不知道是不是使用的http服务器有问题,不过也聊胜于无吧。

相关推荐
huohaiyu5 小时前
从URL到页面的完整解析流程
前端·网络·chrome·url
阿星AI工作室7 小时前
一个简单Demo彻底理解前后端怎么连的丨Figma + Supabase + Vercel
前端·人工智能
aircrushin7 小时前
一拍即传的平替,完全免费的实时照片墙!
前端
鹏北海9 小时前
JSBridge 原理详解
前端
孟健9 小时前
我的网站被黑了:一天灌入 227 万条垃圾数据,AI 写的代码差点让我社死
前端
anOnion9 小时前
构建无障碍组件之Checkbox pattern
前端·html·交互设计
IT枫斗者11 小时前
IntelliJ IDEA 2025.3史诗级更新:统一发行版+Spring Boot 4支持,这更新太香了!
java·开发语言·前端·javascript·spring boot·后端·intellij-idea
N***p36511 小时前
Spring Boot项目接收前端参数的11种方式
前端·spring boot·后端
享誉霸王12 小时前
15、告别混乱!Vue3复杂项目的规范搭建与基础库封装实战
前端·javascript·vue.js·前端框架·json·firefox·html5
a11177613 小时前
飞机躲避炸弹 网页游戏
前端·开源·html·threejs