scriptwelt.org das JavaScript Archiv

Navigation
Startseite
Audio & Sound
Formulare
Cookies
Fenster & Frame
Grafik & Text
Navigation
Suche Scripts
Fun und Spiele
Buttons
Diverse
Tutorials

Kontakt
eine Mail an ScriptWelt.org
Webhosting
Tipps zur Providerwahl und zum Webspace

JavaScript in eine HTML Datei einbinden

Sind JavaScripts sicher?

Links zum Thema JavaSript

Impressum
impressum
Grafik JavaScript / Tageszeitabhäniges Bild

Je nach Tageszeit wird ein anderes Bild ausgegeben. Die Demo zeigt die Ausgabe des Orginalen Javascripts und als normale Ausgabe die beiden Bilder.
Um die Bilder zu ändern, den Pfad in Var r1 und r2 eintragen. Die Zeit lässt in mit el.scr ändern. Body bleibt unverändert.


Autor: unbekannt, Teile des Code sind von Simon Willison
zur Demo

 

in den <head> einfügen
<script type="text/javascript">
function pixTimeChange() {
var t=new Date();
var h = t.getHours();
var r1="../../../Bilder/lp1.gif";
var r2="../../../Bilder/lp1.gif";
var el=document.getElementById('image');

// See the time below. Note: The time is in 24 hour format.
// In the example here, "7" = 7 AM; "17" =5PM.
el.src = (h>=7 && h<17) ? r1 : r2;
}

// Multiple onload function created by: Simon Willison
// http://simonwillison.net/2004/May/26/addLoadEvent/
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}

addLoadEvent(function() {
pixTimeChange();
});
</script>

in <body>

<img src="" id="image" alt="Tgesbilder" />