listen to window event instead