我编写了这个简单的 HTML/JavaScript 代码来以更好的方式在显示器上查看一些 IP 摄像机;当图片不可用时,我希望有前一张图片或至少只有黑色背景,而不是“损坏的图片链接”框。
<body style="margin:0; background-color:black;">
<div style="height:100%; background-color:black; position:fixed;">
<img height="50%" name="Camera1"/>
<img height="50%" name="Camera2"/>
<br>
<img height="50%" name="Camera3"/>
<img height="50%" name="Camera4"/>
</div>
</body>
<script language="JavaScript">
//<!--
function reloadImage()
{
var now = new Date();
var Camera1 = 'http://xxxxxx/cgi-bin/wappaint?camera_no=0&animation=0&name=aa&password=11&time=1346851800&pic_size=2'
var Camera2 = 'http://xxxxxx/cgi-bin/wappaint?camera_no=1&animation=0&name=aa&password=11&time=1346851800&pic_size=2?1346851972719.719'
var Camera3 = 'http://xxxxxx/cgi-bin/wappaint?camera_no=2&animation=0&name=aa&password=11&time=1346851800&pic_size=2?1346851974247.247'
var Camera4 = 'http://xxxxxx/cgi-bin/wappaint?camera_no=3&animation=0&name=aa&password=11&time=1346851800&pic_size=2?1346851975678.678'
if (document.images)
{
document.images.Camera1.src = Camera1 + '?' + now.getTime();
document.images.Camera2.src = Camera2 + '?' + now.getTime();
document.images.Camera3.src = Camera3 + '?' + now.getTime();
document.images.Camera4.src = Camera4 + '?' + now.getTime();
}
setTimeout('reloadImage()',1000);
}
setTimeout('reloadImage()',1000);
//--></script>
会是这样吗?(我写了它,但我不太擅长 JavaScript,所以不知道为什么它不起作用:
//...(inside the if(document.images)...
var image = new Image;
image.onerror = function () { blank(this); }
image.src = Camera1 + '?' + now.getTime();
document.images.Camera1 = image