HOW to continuously refresh any web-page in IE8 & FF

Have you ever felt hassled by a website that provides continuous updates (like cricket scores or live event updates) but requires you to reload the page manually? While Opera browser has an option to automatically reload a web page at pre-defined intervals, Internet Explorer, Firefox & Safari do not have any such feature by default.

I found this code for a browser bookmarklet to automatically refresh any web-page in IE on StackOverlow-

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); }() )


I made the following minor change to it by replacing the use of Microsoft.XMLHTTP ActiveXObject with XMLHttpRequest object so that it works in all new browsers -

javascript:( function(){ i=0;setInterval("i++;var x=new XMLHttpRequest();
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); }() )


Note that in the code snippets I have added newline characters for readability & formatting. Make sure you remove the newline characters so that the whole code is on just one line. The code uses a JavaScript Timer to refresh the page every 5 seconds or 5000 milli-seconds. Change it to set an interval of your choice.

To add the bookmarklet in Firefox, enable the Bookmarks Toolbar (View > Toolbars > Bookmarks Toolbar). Right click on the Bookmarks Toolbar & select New Bookmark. In the Add Bookmark dialog box that opens, type "Refresh Page" as the name of the bookmarklet & paste the second code snippet that's above into the Location textbox as shown in the screenshot below.


A good way to share Bookmarklets (like the jQuerify Bookmarklet or these popular Bookmarklets) is to host it on a webpage as hyperlinks. I could not find a way to embed it on a webpage as a hyperlink (because the code involves using nested quotes) nor a clean way to add the above Bookmarklet to the Favorites Bar in IE8. The following steps to add the Bookmarklet though a little clumsy, get the job done -
1. With the Favorites Bar (View > Toolbars > Favorites bar) open, add any webpage from the tabs as a Favorite.
2. Right click on that Favorite in the Favorites Bar & select Properties from the context menu.
3. In the URL text box of the Web document tab, add the Bookmarklet code shown above


4. A warning "The protocol 'javascript' does not have a registered program. Do you want to keep this target anyway?" appears. Click on the "Yes" button
5. Go to the General tab & type the name for the Bookmarklet as "Refresh Page"


Now whenever you need a webpage to be reloaded automatically, click on the Bookmarklet while you have that page open.

I've tested the Bookmarklet for a short while with Google News. Please report if you find any issues with the Bookmarklet or any other feedback that you may have.

Also see:
View Selection Source in IE
.120