Pages

Wednesday, March 17, 2010

History.go(-1) -> redirect to home page if no history found

//This code will work fine in IE and firefox. Have not tested with others

//create a refernce variable which gets the value 0 if the the browser is ie and 1 if its not

var ref=document.all?0:1;

 //if the page has been initiated from an other page then get back to the previous page or if its fresh
//then redirect to home page

if (window.history.length==ref) {    
   location.href="home page url";
} else    {    
   history.go(-1);
}

No comments:

Post a Comment