Custom function to check if page has loaded or not

Below is a custom function to check whether a page has completely loaded or not. We can call this function anywhere in our project to see if page has loaded or not. If page has fully loaded the status will be complete ,otherwise it will be loading etc. The code is below.

public boolean waitForPageToLoad(){
  JavascriptExecutor js = (JavascriptExecutor)driver;
  String state = (String)js.executeScript("return document.readyState;");
   if(state.equals("complete")
      return true;
  else 
     return false;
}