SHARE
TWEET

Auto Refresh

sweenig Jan 14th, 2014 519 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. This widget automatically refreshes the page at a specified interval.<div id="help"></div>
  2. <script>
  3. var reloading;
  4. function checkReloading(interval) {reloading=setTimeout("window.location.reload();",interval);}
  5. var passedinterval = 0;
  6. var helpdiv = document.getElementById("help");
  7.  
  8. //get the iframe url interval value and store in interval (if passed)
  9. var iframeurl=location.search;
  10. iframeurl=iframeurl.replace('?','');
  11. var iframeargsarray=iframeurl.split('&');
  12. var iframeargsmatrix = new Array(iframeargsarray.length);
  13. for (var i = 0; i < iframeargsarray.length; i++){iframeargsmatrix[i] = new Array(2);iframeargsmatrix[i] = iframeargsarray[i].split('=');}
  14. for (var j=0; j < iframeargsmatrix.length; j++){if(iframeargsmatrix[j][0] == 'interval'){passedinterval = iframeargsmatrix[j][1];break;}}
  15. passedinterval=passedinterval*60000;
  16. //passedinterval contains the iframe's interval.  If 0, no interval was passed.
  17. if(passedinterval != 0){
  18.         var d=new Date();var h=d.getHours();var m=d.getMinutes();
  19.         if (m<10) { m='0' + m ; }
  20.         if (h>12) { var ap='pm';h=h-12; } else { var ap='am'; }
  21.         checkReloading(passedinterval);
  22.         helpdiv.innerHTML = 'Last refreshed: ' + h + ':' + m + ' ' + ap + ' ('+Date()+')<br />You have specified an interval of ' + passedinterval/60000 +' minutes. <br />Now edit this view and set the height to 0 to maximize available screen real estate. You should probably change the title of the browser view so that it indicates the new interval.';
  23. } else {
  24.         var helptext = 'You have not specified a interval within the browser view\'s target URL.';
  25.         helptext += '<br />Add ?interval=X to the browser view URL where X is the number of minutes between refreshes.';
  26.         helpdiv.innerHTML = helptext;
  27. }
  28. </script>
RAW Paste Data
Top