Automatically Refresh Page On Focus

05 May 2009

When developing you refresh the browser quite a lot, and that’s why this simple javascript is very useful.

The browser refreshes automatically when you give it focus… (only if the url contains the word ‘local’ as in ‘localhost’, ‘project.local’ etc.)

window.onload = function() {
	onfocus = function () {
		onfocus = function () {
			if(document.URL.indexOf("local") != -1){
				location.reload (true);
			}
		}
	}
}
Jankees van Woezik profile picture

Hello, I'm Jankees van Woezik

Like this post? Follow me at @jankeesvw on Twitter