More compatible implementation of heart.quit()

This version works correctly and has been tested in Firefox, Chrome, and
Safari.