<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d8211560\x26blogName\x3dTech+Tips,+Tricks+%26+Trivia\x26publishMode\x3dPUBLISH_MODE_BLOGSPOT\x26navbarType\x3dBLUE\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttp://mvark.blogspot.com/search\x26blogLocale\x3den\x26v\x3d2\x26homepageUrl\x3dhttp://mvark.blogspot.com/\x26vt\x3d-5147029996388199615', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>

Tech Tips, Tricks & Trivia

by 'Anil' Radhakrishna
An architect's notes, experiments, discoveries and annotated bookmarks.

Search from over a hundred HOW TO articles, Tips and Tricks


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

Labels: , ,

Tweet this | Google+ it | Share on FB

« Home | Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »

Posted by Anonymous Anonymous | 4/30/2011 01:23:00 AM

neat    



Posted by Anonymous Anonymous | 7/20/2011 06:23:00 AM

Cool! I don't get how to use this with Google Chrome, though. I'm trying to refresh a YouTube video continuously : P    



»

Post a Comment