Changed use of $window.unload to $window.bind("unload")

- #2240