Added onpagebefore and onpageafter events