implement the function about close window or leave the page