Adding window before unload method.