added onpopstate event to restore history