views:

117

answers:

3

One of my coworkers needs a piece of data from a 3rd party website. That data gets posted to a site each morning at an arbitrary time. He has to sit there and click refresh in his browser every 10 seconds until it shows up. He asked me if I could write something to make that page auto refresh every X seconds so he can leave it open on one monitor and do some other work on the other.

Normally, I would write a little screen scraper in perl and email him the number he wants when it comes out... But I thought it might be fun to write a bookmarklet.

I got as far as this:

javascript:(function(){setInterval("location.reload(true);",10000);})()

But cannot figure out how to make the effect persist after the page reloads. Is it possible? If so... how?

This would be easy in Firefox/Greasemonkey... but this guy is stuck running a locked-down version of IE6. He can install a bookmarklet, but cannot install the IE equivalent of GM (if that even exists)

Please point me in the right direction here... is it possible to have Javascript persist after reloading a page?

+1  A: 

You could try some AJAX to GET the page, then replace the innerHTML of the current body with the new body.

geowa4
I ended up with the following naive code which appears to work for him.<br />javascript:( function(){ i=0;setInterval("i++;var x=new ActiveXObject('Microsoft.XMLHTTP');x.open('GET',location.href+'?'+i,true);x.setRequestHeader('Content-Type','application/x-www-form-urlencoded');x.onreadystatechange=function(){if(x.readyState==4){document.body.innerHTML=x.responseText;}};x.send(null);",5000); }() )
Sukotto
A: 

You could try having the bookmarklet open a new window and writing the content of that window to reload the parent via something like

window.opener.document.location.reload();

Justin Wignall
A: 

Not sure about a bookmarklet, but this examples refreshes an Iframe on the page at an interval, which should do the trick...

<!DOCTYPE html>

<html>
  <head>
    <title>Auto Refresh</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <script type="text/javascript">
      window.onload = function() {
        var url = 'http://www.google.com';

        setInterval(function() {
          document.getElementById('thisFrame').src = url;
        }, 10000)
      }
    </script>
  </head>
  <body>
    <iframe id="thisFrame" src="http://www.google.com" frameborder="0" width="100%"></iframe>
  </body>
</html>
Josh Stodola