Safely attach a handler to window.onload.