I've inherited the following code:
// if parent window is closed or changed, close popups
window.onbeforeunload = function () { /* some cleanup stuff */ };
window.onchange = function () { /* same exact cleanup stuff */ };
The window.onchange
line is causing problems;
On Chrome, it fires for no apparent reasons (with undesirable cleanup results). It doesn't fire in IE11.
Can I safely get rid of this line?
The Mozilla guys don't give too much information:
An event handler for change events sent to the window.
...and The Internet in general doesn't seem to have much to say about it either.
So what exactly triggers windows.onchange
? Does it work on all major browsers? (If not, then that's a good enough assurance for me that I can delete it.)
I've inherited the following code:
// if parent window is closed or changed, close popups
window.onbeforeunload = function () { /* some cleanup stuff */ };
window.onchange = function () { /* same exact cleanup stuff */ };
The window.onchange
line is causing problems;
On Chrome, it fires for no apparent reasons (with undesirable cleanup results). It doesn't fire in IE11.
Can I safely get rid of this line?
The Mozilla guys don't give too much information:
An event handler for change events sent to the window.
...and The Internet in general doesn't seem to have much to say about it either.
So what exactly triggers windows.onchange
? Does it work on all major browsers? (If not, then that's a good enough assurance for me that I can delete it.)
Change events fire when a form control is changed. In the demo below, type something, then hit Tab to blur the control and trigger the change event.
onchange = function (e) { console.log(e.target); }
<input>
Events bubble, so the listener does not need to be directly attached to the input.
It's impossible to say if it is "safe to remove" in your example, because there is no context provided about what is being cleaned up so we can't tell if it is necessary / useful / harmful to perform the clean up after every change event.