Я пытаюсь создать страницу, которая отображает и обновляет изображение с веб-камеры ( camimg.jpg ), но отображает статическое изображение ( notlive.jpg ), еслиизображение не было обновлено в последнее время.Я обнаружил скрипт AJAXCam , который служит для перезагрузки «живого» изображения через заданный интервал ( 15 секунд ), но без опыта Javascript я не могу понятьКак определить, когда изображение было обновлено в последний раз, чтобы решить, следует ли отображать camimg.jpg или notlive.jpg.
Мой ограниченный опыт программирования заставляет меня думать, что это должно быть что-то вроде:
pageLoaded = time page loaded in browser
imageUpdated = time the image was uploaded to server
if imageUpdated is not within 20 seconds of pageLoaded:
display notlive.jpg
else:
run AJAXCam
Код AJAXCam (первоначально называемый <body onLoad="holdUp()">
) выглядит следующим образом:
<script type="text/javascript">
<!--
//
//AJAXCam v0.8b (c) 2005 Douglas Turecek http://www.ajaxcam.com
//
function holdUp()
{
//
// This function is first called either by an onLoad event in the <body> tag
// or some other event, like onClick.
//
// Set the value of refreshFreq to how often (in seconds)
// you want the picture to refresh
//
refreshFreq=15;
//
//after the refresh time elapses, go and update the picture
//
setTimeout("freshPic()", refreshFreq*1000);
}
function freshPic()
{
//
// Get the source value for the picture
// e.g. http://www.mysite.com/doug.jpg and
//
var currentPath=document.campic.src;
//
// Declare a new array to put the trimmed part of the source
// value in
//
var trimmedPath=new Array();
//
// Take everything before a question mark in the source value
// and put it in the array we created e.g. doug.jpg?0.32234 becomes
// doug.jpg (with the 0.32234 going into the second array spot
//
trimmedPath=currentPath.split("?");
//
// Take the source value and tack a qustion mark followed by a random number
// This makes the browser treat it as a new image and not use the cached copy
//
document.campic.src = trimmedPath[0] + "?" + Math.random();
//
// Go back and wait again.
holdUp();
}
// -->
</script>
Возможно ли то, что я пытаюсь достичь, даже возможно?И если да, то как бы я это реализовал?Заранее спасибо за помощь!