以HTML格式自动刷新图像

编程入门 行业动态 更新时间:2024-10-21 18:39:40
本文介绍了以HTML格式自动刷新图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用以下代码

I am using following code

<html> <script> var newImage = new Image(); function updateImage() { if(newImageplete) { newImage.src = document.getElementById("img").src; var temp = newImage.src; document.getElementById("img").src = newImage.src; newImage = new Image(); newImage.src = temp+"?" + new Date().getTime(); } setTimeout(updateImage, 1000); }; </script> <body onload="updateImage();"> <img id="img" src="cameraURI" style="position:absolute;top:0;left:0;height:50%;width:50%"/> </body> </html>

但是我的图片没有被刷新。请注意,对于我的应用程序目的,我无法在脚本中使用任何url。

But my image is not getting refreshed. Note that for my application purpose, I cant use any url in script.

我知道我需要删除 newImage.src = document.getElementById img).src; ,并且需要在同一个文件中放置函数updateImage(),但是如果我这样做, document.getElementById().src被设置为NULL ,我不能使用自动刷新HTML页面。所以对这个文件的任何帮助??

I know I need to remove newImage.src = document.getElementById("img").src; and need to place over function updateImage() in same file but if I do this, I am getting error as document.getElementById(" ").src is set to NULL and I cant use auto-refresh HTML page. So any help on this file??

推荐答案

试试这个

function refresh(node) { var times = 3000; // gap in Milli Seconds; (function startRefresh() { var address; if(node.src.indexOf('?')>-1) address = node.src.split('?')[0]; else address = node.src; node.src = address+"?time="+new Date().getTime(); setTimeout(startRefresh,times); })(); } window.onload = function() { var node = document.getElementById('img'); refresh(node); // you can refresh as many images you want just repeat above steps }

更多推荐

以HTML格式自动刷新图像

本文发布于:2023-11-26 13:10:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633990.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   格式   HTML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!