Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. <script>
  2. var xmlHttp, srvTime, thisDay;
  3. function getSrvTime() {
  4. try {
  5. xmlHttp = new XMLHttpRequest();
  6. }
  7. catch (err1) {
  8. try {
  9. xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
  10. }
  11. catch (err2) {
  12. try {
  13. xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
  14. }
  15. catch (eerr3) {
  16. // Browser didn't support ajax so use client time
  17. return new Date();
  18. }
  19. }
  20. }
  21. xmlHttp.open('HEAD', window.location.href.toString(), false);
  22. xmlHttp.setRequestHeader("Content-Type", "text/html");
  23. xmlHttp.send('');
  24. return xmlHttp.getResponseHeader("Date");
  25. }
  26.  
  27. function updateSchedule() {
  28. var now = new Date(srvTime());
  29. var currentDay = now.getDay();
  30.  
  31. if (currentDay !== thisDay) {
  32. // the day has changed so update div using jQuery
  33. jQuery("#schedule").load(location.href + " #schedule");
  34.  
  35. // set thisDay to the currentDay (this means the function will only update once a day)
  36. thisDay = currentDay;
  37. }
  38. }
  39.  
  40. (function($, window){
  41. $(function(){
  42. // get server time on init
  43. var now = new Date(getSrvTime());
  44.  
  45. // set thisDay to the current day
  46. thisDay = now.getDay();
  47.  
  48. // set the interval for polling (every 30 seconds
  49. setInterval(function() {
  50. updateSchedule();
  51. }, 30000);
  52. });
  53. })(jQuery, window);
  54. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement