Use addEventListener if possible. Fixes issue 6680