• Das Erstellen neuer Accounts wurde ausgesetzt. Bei berechtigtem Interesse bitte Kontaktaufnahme über die üblichen Wege. Beste Grüße der Admin

Webcam-Foto per JavaScript einbinden

abelius-kiel

New member
HAllo allerseits,

ein herzlicher Gruß aus Kiel, vielen Dank für die Aufnahme.

Mein Hobby sind seit vielen Jahren IP-Cams und Webcams, die ich auf meiner Homepage einstelle. Das jeweilige jpeg-Bild der Kamera baue ich mit folgendem JavaScriptz ein, um das Bild zum "Laufen" zu bringen. Also ein refresh:

Code:
<script language="javascript">
errorimg1= 0;
function LoadImage1()
{
uniq1 = Math.random();
document.images.webcam1.src = "http://nordbiene.selfhost.eu:8181/cam.jpg?uniq="+uniq1;
}
function ErrorImage1()
{
errorimg1++;
if (errorimg1>1){
document.images.webcam1.onload = "";
document.images.webcam1.src = "http://live.honey-bees.de/error.jpg";
}else{
document.images.webcam1.src = "http://nordbiene.selfhost.eu:8181/cam.jpg?uniq="+uniq1;
}
}
function DoIt1()
{
errorimg1=0;
window.setTimeout("LoadImage1();", 15);
}
document.write('<img src="http://live.honey-bees.de/pause.jpg" id="webcam1" name="webcam1" onload="DoIt1()" onerror="ErrorImage1()" width=600 height=450 alt="Webcam-Stream">');
</script>

Bei folgender Kamera funktioniert dies aber nicht. Frage: Warum??

Code:
<script language="javascript">
errorimg1= 0;
function LoadImage1()
{
uniq1 = Math.random();
document.images.webcam1.src = "http://nordbiene.selfhost.eu:8080/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=gast&pwd=gast?uniq="+uniq1;
}
function ErrorImage1()
{
errorimg1++;
if (errorimg1>1){
document.images.webcam1.onload = "";
document.images.webcam1.src = "http://live.honey-bees.de/error.jpg";
}else{
document.images.webcam1.src = "http://nordbiene.selfhost.eu:8080/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=gast&pwd=gast?uniq="+uniq1;
}
}
function DoIt1()
{
errorimg1=0;
window.setTimeout("LoadImage1();", 15);
}
document.write('<img src="http://live.honey-bees.de/pause.jpg" id="webcam1" name="webcam1" onload="DoIt1()" onerror="ErrorImage1()" width=600 height=450 alt="Webcam-Stream">');
</script>

Für eine Hilfe wäre ich sehr dankbar.

LG
Kai
 
PS: der Code ist aber mehr als suboptimal: globale Variablen, String an window.setTimout() übergeben, kein Einrückung, mehrere Stellen, wo man die URL pflegen muss, document.write()...

Zu document.write:
http://www.w3.org/html/wg/drafts/html/CR/webappapis.html#dynamic-markup-insertion schrieb:
This method has very idiosyncratic behavior. In some cases, this method can affect the state of the HTML parser while the parser is running, resulting in a DOM that does not correspond to the source of the document (e.g. if the string written is the string "<plaintext>" or "<!--"). In other cases, the call can clear the current page first, as if document.open( ) had been called. In yet more cases, the method is simply ignored, or throws an exception. To make matters worse, the exact behavior of this method can in some cases be dependent on network latency, which can lead to failures that are very hard to debug. For all these reasons, use of this method is strongly discouraged.
 
Zurück
Oben