change the unlocking to the unload event so that it is possible to bind the onbeforeunload event

without messing with the locking (to add a leave the page confirmation for example)