16-07-2009

Javascript location.replace and location.href redirect

If the browser supports it you can use location.replace to replace the current page in the browsers history with another page - so that clicking back will skip the redirection page. It's good to add a location.href redirect for browsers that don't support it.

if (location.replace){ 
 
	location.replace('/');
 
} else {
 
	location.href ='/'; 
 
}
 

Also beware of this IE location.replace bug http://splintor.wordpress.com/2007/04/12/locationreplace-and-back-button-bug-in-ie/

Comments:

Your comment:

»

 

[x]