check if window is undefined before operating on it