Refactor empty() to work better on non-IE browsers.

1. Test node.innerHTML rather than node.canHaveChildren(), since the latter
only works on IE.
2. Limit empty(parent) to orphaning parent's children, rather than orphaning
parent's grandchildren.

Fixes #17869.
Document addOnUnload() and add addOnWindowUnload() as deprecated, refs #17870.