ishats
2019-08-21
I want to be able to intercept window.location.replace
calls. Overriding it isn’t an option, since it’s readonly and creating a wrapper function that consumers need to call instead is also annoying, especially because some of the consumers in my case are third parties.
I want to be able to detect what type of navigation is happening, and one place from which to do that is the onbeforeunload
handler. Could its event contain additional information about what triggered the unload (e.g. location.assign
, location.replace
, <a target="..." />
[with information about the target], etc.)? Or is there another place where that information could be exposed… Alternatively, detecting a location-replace-type event would be an option here too.