Fix window.addEventListener/attachEvent calls and add fallback case if
neither deferred method is available.