Added a 'beforeunload' shim for iOs, extendable to other devices which don't support 'beforeunload' events, as well as tests.