Added support for onclose.