snipt

Ctrl+h for KB shortcuts

JavaScript

IE friendly addEventListener

1
2
3
4
5
if (window.addEventListener) {
    
} else if (window.attachEvent) {

}
https://snipt.net/embed/25a59766ebbc55486598c5e1a7c025f8/
/raw/25a59766ebbc55486598c5e1a7c025f8/
25a59766ebbc55486598c5e1a7c025f8
js
JavaScript
6
2019-07-20T16:23:27
True
False
False
/api/public/snipt/77414/
ie-friendly-addeventlistener
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">if</span> <span class="p">(</span><span class="nb">window</span><span class="p">.</span><span class="nx">addEventListener</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nb">window</span><span class="p">.</span><span class="nx">attachEvent</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
addEventListener, compatibility, ie, javascript, js