var init = 'sounds/whoson_aktiviert.mp3'; //var init ='sounds/0.mp3'; var on = 'sounds/user_online_2.mp3'; domain = document.domain; path = window.location.pathname; // /chat/whoson.php if (path.indexOf("whoson") != -1) { var dir = path.replace("/whoson.php",""); var install = "//" + domain + dir; } else { var install = "//" + domain + "/chat"; } // zuerst der AJAX Teil: // http://aleembawany.com/2005/09/01/ajax-instant-tutorial/ function loadurl(dest) { try { xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { /* do nothing */ } xmlhttp.onreadystatechange = triggered; xmlhttp.open("POST", dest); xmlhttp.send(null); } function triggered() { if (xmlhttp.readyState == 4) document.getElementById("output").innerHTML =xmlhttp.responseText; } // und jetzt auto-refresh und sounds: var anw = 0; function playsound(typ) { // die standardkonforme Lösung für alle Browser if (document.getElementById('ton')) { document.getElementById("ton").innerHTML = ''; } } function refresh() { // in folgender Zeile evtl. den kompletten Pfad eingeben: loadurl('anwesend.php'); y=document.getElementById("output").innerHTML; x=y.length; if (y.indexOf('noscript') != -1) { anw = 0; } else if (y.indexOf('niemand') != -1) { changeFavicon('img/traurig_ico.png'); document.title = "Leider niemand im Chat"; anw = 0; } else { changeFavicon('img/favicon.ico'); document.title = " Chatter anwesend"; if (anw != 1) { playsound(on); } anw = 1; } update_refresh = setTimeout(refresh, 3000); } document.head = document.head || (document.getElementsByTagName('head')[0]); function changeFavicon(src) { src = src+'?='+Math.random(); // so wird das cachen zuverlässig vermieden var link = document.createElement('link'), oldLink = document.getElementById('dynamic-favicon'); link.id = 'dynamic-favicon'; link.rel = 'shortcut icon'; link.href = src; if (oldLink) { document.head.removeChild(oldLink); } document.head.appendChild(link); } window.onload = function () { playsound(init); // playsound initialisieren refresh(); }