A new Riff-radio.org site with a static approach.

refresh.js~ 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. var seconds = 10;
  2. var divid = "shoutcastdiv";
  3. var url = "/shoutcastajax/shoutcast_song_title.php";
  4. ////////////////////////////////
  5. //
  6. // Refreshing the DIV
  7. //
  8. ////////////////////////////////
  9. function refreshdiv(){
  10. // The XMLHttpRequest object
  11. var xmlHttp;
  12. try{
  13. xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
  14. }
  15. catch (e){
  16. try{
  17. xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
  18. }
  19. catch (e){
  20. try{
  21. xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  22. }
  23. catch (e){
  24. alert("Your browser does not support AJAX.");
  25. return false;
  26. }
  27. }
  28. }
  29. // Timestamp for preventing IE caching the GET request
  30. fetch_unix_timestamp = function()
  31. {
  32. return parseInt(new Date().getTime().toString().substring(0, 10))
  33. }
  34. var timestamp = fetch_unix_timestamp();
  35. var nocacheurl = url+"?t="+timestamp;
  36. // The code...
  37. xmlHttp.onreadystatechange=function(){
  38. if(xmlHttp.readyState==4){
  39. document.getElementById(divid).innerHTML=xmlHttp.responseText;
  40. setTimeout('refreshdiv()',seconds*1000);
  41. }
  42. }
  43. xmlHttp.open("GET",nocacheurl,true);
  44. xmlHttp.send(null);
  45. }
  46. // Start the refreshing process
  47. window.onload = function startrefresh(){
  48. setTimeout('refreshdiv()',seconds*1000);
  49. }