即使我不重新加载,如何自动检测网页更改

时间:2012-10-23 02:51:12

标签: javascript automation alert webpage

  

可能重复:
  How does Stack Overflow notify of server-side events without a page reload? I see no request in Firebug

有没有办法提醒用户,以便他们可以在页面上有变化时执行重新加载?

<script type="text/javascript">
     var page = 'data/apps/<? echo $_SESSION['name']; ?><? echo $_SESSION['last'];>App.html', lM;

function checkModified() {
   $.get(page, function(a, b, x) {
      var mod = (x.getResponseHeader('Last-Modified')) ? x.getResponseHeader('Last-Modified') : x.getResponseHeader('Content-Length');
      if (lM != mod) {
         lM = mod;
         console.log('Fetched');
         alert 
("Changes on "+<? echo $_SESSION['name']; ?><? echo $_SESSION['last']; ?>+"App.html has been made");
      }
   });
}

setInterval(checkModified, 5000); // every 5 seconds
</script>

这两个页​​面都位于一个域内。

0 个答案:

没有答案