Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Please feel free to update this list if you see any errors/omissions etc. </p> <p><strong>Note:</strong> IE9 fixes many of the following issues, so a lot of this only applies to IE8 and below and to a certain extent IE9 in quirks mode. For example, IE9 supports SVG, <code>&lt;canvas&gt;</code>, <code>&lt;audio&gt;</code> and <code>&lt;video&gt;</code> natively, however you must <a href="http://blogs.msdn.com/b/ie/archive/2010/09/03/same-markup-using-canvas-audio-and-video.aspx" rel="nofollow noreferrer">enable standards compliance mode</a> for them to be available.</p> <hr> <h2>General:</h2> <ul> <li><p><strong>Problems with partially loaded documents:</strong> It’s a good idea to add your JavaScript in a <code>window.onload</code> or similar event as IE doesn’t support many operations in partially loaded documents.<P></p></li> <li><p><strong>Differing attributes</strong>: In CSS, it's <code>elm.style.styleFloat</code> in IE vs <code>elm.style.cssFloat</code> in Firefox. In <code>&lt;label&gt;</code> tags the <code>for</code> attribute is accessed with <code>elm.htmlFor</code> in IE vs <code>elm.for</code> in Firefox. Note that <code>for</code> is reserved in IE so <code>elm['for']</code> is probably a better idea to stop IE from raising an exception.</p></li> </ul> <hr> <h2>Base JavaScript language:</h2> <ul> <li><p><strong>Access characters in strings</strong>: <code>'string'[0]</code> isn’t supported in IE as it’s not in the original JavaScript specifications. Use <code>'string'.charAt(0)</code> or <code>'string'.split('')[0]</code> noting that accessing items in arrays is significantly faster than using <code>charAt</code> with strings in IE (though there's some initial overhead when <code>split</code> is first called.)<P></p></li> <li><p><strong>Commas before the end of objects:</strong> e.g. <code>{'foo': 'bar',}</code> aren't allowed in IE.</p></li> </ul> <hr> <h2>Element-specific issues:</h2> <ul> <li><p><strong>Getting the <code>document</code> of an IFrame</strong>:</p> <ul> <li><strong>Firefox and IE8+:</strong> <code>IFrame.contentDocument</code> (IE started supporting this <a href="https://stackoverflow.com/a/6582370/304185">from version 8</a>.)</li> <li><strong>IE:</strong> <code>IFrame.contentWindow.document</code></li> <li>(<code>IFrame.contentWindow</code> refers to the <code>window</code> in both browsers.)<p></li> </ul></li> <li><p><strong>Canvas:</strong> Versions of IE before IE9 don't support the <code>&lt;canvas&gt;</code> element. IE does support <a href="http://en.wikipedia.org/wiki/Vector_Markup_Language" rel="nofollow noreferrer">VML</a> which is a similar technology however, and <a href="http://code.google.com/p/explorercanvas/" rel="nofollow noreferrer">explorercanvas</a> can provide an in-place wrapper for <code>&lt;canvas&gt;</code> elements for many operations. Be aware that IE8 in standards compliance mode is many times slower and has many more glitches than when in quirks mode when using VML.</p></li> <li><p><strong>SVG:</strong> IE9 supports SVG natively. IE6-8 can support SVG, but only with <a href="http://www.planetsvg.com/content/svg-solutions-internet-explorer" rel="nofollow noreferrer">external plugins</a> with only some of those plugins supporting JavaScript manipulation.</p></li> <li><p><strong><code>&lt;audio&gt;</code> and <code>&lt;video&gt;</code>:</strong> are only supported in IE9.</p></li> <li><p><strong>Dynamically creating radio buttons:</strong> IE &lt;8 has a bug which makes radio buttons created with <code>document.createElement</code> uncheckable. See also <a href="https://stackoverflow.com/questions/118693/how-do-you-dynamically-create-a-radio-button-in-javascript-that-works-in-all-brow/119079">How do you dynamically create a radio button in Javascript that works in all browsers?</a> for a way to get around this.</p></li> <li><p><strong>Embedded JavaScript in <code>&lt;a href&gt;</code> tags and <code>onbeforeunload</code> conflicts in IE:</strong> If there's embedded JavaScript in the <code>href</code> part of an <code>a</code> tag (e.g. <code>&lt;a href="javascript: doStuff()"&gt;</code> then IE will always show the message returned from <code>onbeforeunload</code> unless the <code>onbeforeunload</code> handler is removed beforehand. See also <a href="https://stackoverflow.com/questions/2858057/javascript-function-on-web-page-close/2858329">Ask for confirm when closing a tab</a>. </p></li> <li><p><strong><code>&lt;script&gt;</code> tag event differences:</strong> <code>onsuccess</code> and <code>onerror</code> aren't supported in IE and are replaced by an IE-specific <code>onreadystatechange</code> which is fired regardless of whether the download succeeded or failed. See also <a href="http://unixpapa.com/js/dyna.html" rel="nofollow noreferrer">JavaScript Madness</a> for more info.</p></li> </ul> <hr> <h2>Element size/position/scrolling and mouse position:</h2> <ul> <li><p><strong>Getting element size/position</strong>: width/height of elements is sometimes <code>elm.style.pixelHeight/Width</code> in IE rather than <code>elm.offsetHeight/Width</code>, but neither is reliable in IE, especially in quirks mode, and sometimes one gives a better result than the other. </p> <p><code>elm.offsetTop</code> and <code>elm.offsetLeft</code> are often incorrectly reported, leading to finding positions of elements being incorrect, which is why popup elements etc are a few pixels off in a lot of cases. </p> <p>Also note that if an element (or a parent of the element) has a <code>display</code> of <code>none</code> then IE will raise an exception when accessing size/position attributes rather than returning <code>0</code> as Firefox does. </p></li> <li><p><strong>Get the screen size</strong> (Getting the viewable area of the screen):</p> <ul> <li><strong>Firefox:</strong> <code>window.innerWidth/innerHeight</code></li> <li><strong>IE standards mode:</strong> <code>document.documentElement.clientWidth/clientHeight</code></li> <li><strong>IE quirks mode:</strong> <code>document.body.clientWidth/clientHeight</code><P></li> </ul></li> <li><p><strong>Document scroll position/mouse position</strong>: This one is actually not defined by the w3c so is non-standard even in Firefox. To find the <code>scrollLeft</code>/<code>scrollTop</code> of the <code>document</code>:</p> <ul> <li><strong>Firefox and IE in quirks mode:</strong> <code>document.body.scrollLeft/scrollTop</code></li> <li><strong>IE in standards mode:</strong> <code>document.documentElement.scrollLeft/scrollTop</code></li> <li><p><strong>NOTE:</strong> Some other browsers use <code>pageXOffset</code>/<code>pageYOffset</code> as well.</p> <pre><code>function getDocScrollPos() { var x = document.body.scrollLeft || document.documentElement.scrollLeft || window.pageXOffset || 0, y = document.body.scrollTop || document.documentElement.scrollTop || window.pageYOffset || 0; return [x, y]; }; </code></pre></li> </ul> <p>In order to get the position of the mouse cursor, <code>evt.clientX</code> and <code>evt.clientY</code> in <code>mousemove</code> events will give the position relative to the document <em>without adding the scroll position</em> so the previous function will need to be incorporated:</p> <pre><code>var mousepos = [0, 0]; document.onmousemove = function(evt) { evt = evt || window.event; if (typeof evt.pageX != 'undefined') { // Firefox support mousepos = [evt.pageX, evt.pageY]; } else { // IE support var scrollpos = getDocScrollPos(); mousepos = [evt.clientX+scrollpos[0], evt.clientY+scrollpos[1]]; }; }; </code></pre></li> </ul> <hr> <h2>Selections/ranges:</h2> <ul> <li><p><strong><code>&lt;textarea&gt;</code> and <code>&lt;input&gt;</code> selections</strong>: <code>selectionStart</code> and <code>selectionEnd</code> are not implemented in IE, and there's a proprietary "ranges" system in its place, see also <a href="https://stackoverflow.com/questions/263743/how-to-get-cursor-position-in-textarea">Caret position in textarea, in characters from the start</a>.</p></li> <li><p><strong>Getting the currently selected text in the document:</strong> </p> <ul> <li><strong>Firefox:</strong> <code>window.getSelection().toString()</code></li> <li><strong>IE:</strong> <code>document.selection.createRange().text</code><P></li> </ul></li> </ul> <hr> <h2>Getting elements by ID:</h2> <ul> <li><p><code>document.getElementById</code> can also refer to the <code>name</code> attribute in forms (depending which is defined first in the document) so it's best not to have different elements which have the same <code>name</code> and <code>id</code>. This dates back to the days when <code>id</code> wasn't a w3c standard. <code>document.all</code> (<a href="https://stackoverflow.com/questions/2408424/">a proprietary IE-specific property</a>) is significantly faster than <code>document.getElementById</code>, but it has other problems as it always prioritizes <code>name</code> before <code>id</code>. I personally use this code, falling back with additional checks just to be sure:</p> <pre><code>function getById(id) { var e; if (document.all) { e = document.all[id]; if (e &amp;&amp; e.tagName &amp;&amp; e.id === id) { return e; }; }; e = document.getElementById(id); if (e &amp;&amp; e.id === id) { return e; } else if (!e) { return null; } else { throw 'Element found by "name" instead of "id": ' + id; }; }; </code></pre></li> </ul> <hr> <h2>Problems with read only innerHTML:</h2> <ul> <li><p>IE does <a href="http://msdn.microsoft.com/en-us/library/ie/ms533897%28v=vs.85%29.aspx" rel="nofollow noreferrer">not support</a> setting the innerHTML of <code>col</code>, <code>colGroup</code>, <code>frameSet</code>, <code>html</code>, <code>head</code>, <code>style</code>, <code>table</code>, <code>tBody</code>, <code>tFoot</code>, <code>tHead</code>, <code>title</code>, and <code>tr</code> elements. Here's a function which works around that for table-related elements:</p> <pre><code>function setHTML(elm, html) { // Try innerHTML first try { elm.innerHTML = html; } catch (exc) { function getElm(html) { // Create a new element and return the first child var e = document.createElement('div'); e.innerHTML = html; return e.firstChild; }; function replace(elms) { // Remove the old elements from 'elm' while (elm.children.length) { elm.removeChild(elm.firstChild); } // Add the new elements from 'elms' to 'elm' for (var x=0; x&lt;elms.children.length; x++) { elm.appendChild(elms.children[x]); }; }; // IE 6-8 don't support setting innerHTML for // TABLE, TBODY, TFOOT, THEAD, and TR directly var tn = elm.tagName.toLowerCase(); if (tn === 'table') { replace(getElm('&lt;table&gt;' + html + '&lt;/table&gt;')); } else if (['tbody', 'tfoot', 'thead'].indexOf(tn) != -1) { replace(getElm('&lt;table&gt;&lt;tbody&gt;' + html + '&lt;/tbody&gt;&lt;/table&gt;').firstChild); } else if (tn === 'tr') { replace(getElm('&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;' + html + '&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;').firstChild.firstChild); } else { throw exc; }; }; }; </code></pre> <p>Also note that IE requires adding a <code>&lt;tbody&gt;</code> to a <code>&lt;table&gt;</code> before appending <code>&lt;tr&gt;</code>s to that <code>&lt;tbody&gt;</code> element when creating using <code>document.createElement</code>, for example:</p> <pre><code>var table = document.createElement('table'); var tbody = document.createElement('tbody'); var tr = document.createElement('tr'); var td = document.createElement('td'); table.appendChild(tbody); tbody.appendChild(tr); tr.appendChild(td); // and so on </code></pre></li> </ul> <hr> <h2>Event differences:</h2> <ul> <li><p><strong>Getting the <code>event</code> variable:</strong> DOM events aren't passed to functions in IE and are accessible as <code>window.event</code>. One common way of getting the event is to use e.g. <BR><code>elm.onmouseover = function(evt) {evt = evt||window.event}</code><BR>which defaults to <code>window.event</code> if <code>evt</code> is undefined.</p></li> <li><p><strong>Key event code differences:</strong> Key event codes vary wildly, though if you look at <a href="http://www.quirksmode.org/js/keys.html" rel="nofollow noreferrer">Quirksmode</a> or <a href="http://unixpapa.com/js/key.html" rel="nofollow noreferrer">JavaScript Madness</a>, it's hardly specific to IE, Safari and Opera are different again.</p></li> <li><p><strong>Mouse event differences:</strong> the <code>button</code> attribute in IE is a bit-flag which allows multiple mouse buttons at once:</p> <ul> <li><strong>Left:</strong> 1 (<code>var isLeft = evt.button &amp; 1</code>)</li> <li><strong>Right:</strong> 2 (<code>var isRight = evt.button &amp; 2</code>)</li> <li><p><strong>Center:</strong> 4 (<code>var isCenter = evt.button &amp; 4</code>)<P></p> <p>The W3C model (supported by Firefox) is less flexible than the IE model is, with only a single button allowed at once with left as <code>0</code>, right as <code>2</code> and center as <code>1</code>. Note that, as Peter-Paul Koch <a href="http://www.quirksmode.org/js/events_properties.html#button" rel="nofollow noreferrer">mentions</a>, this is very counter-intuitive, as <code>0</code> usually means 'no button'.</p> <p><code>offsetX</code> and <code>offsetY</code> are <a href="http://www.quirksmode.org/dom/w3c_cssom.html#mousepos" rel="nofollow noreferrer">problematic</a> and it's probably best to avoid them in IE. A more reliable way to get the <code>offsetX</code> and <code>offsetY</code> in IE would be to <a href="https://stackoverflow.com/questions/160144/find-x-y-of-an-html-element-with-javascript">get the position</a> of the relatively positioned element and subtract it from <code>clientX</code> and <code>clientY</code>.</p> <p>Also note that in IE to get a double click in a <code>click</code> event you'd need to register both a <code>click</code> and <code>dblclick</code> event to a function. Firefox fires <code>click</code> as well as <code>dblclick</code> when double clicking, so IE-specific detection is needed to have the same behaviour.</p></li> </ul></li> <li><p><strong>Differences in the event handling model:</strong> Both the proprietary IE model and the Firefox model support handling of events from the bottom up, e.g. if there are events in both elements of <code>&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;</code> then events will trigger in the <code>span</code> <em>then</em> the <code>div</code> rather than the order which they're bound if a traditional e.g. <code>elm.onclick = function(evt) {}</code> was used. <P>"Capture" events are generally only supported in Firefox etc, which will trigger the <code>div</code> then the <code>span</code> events in a top down order. IE has <code>elm.setCapture()</code> and <code>elm.releaseCapture()</code> for redirecting mouse events from the document to the element (<code>elm</code> in this case) before processing other events, but they have a number of performance and other issues so should probably be avoided. </p> <ul> <li><p><strong>Firefox:</strong><P> <strong>Attach</strong>: <code>elm.addEventListener(type, listener, useCapture [true/false])</code><BR> <strong>Detach</strong>: <code>elm.removeEventListener(type, listener, useCapture)</code><BR> (<code>type</code> is e.g. <code>'mouseover'</code> without the <code>on</code>)<P></p></li> <li><p><strong>IE:</strong> Only a single event of a given type on an element can be added in IE - an exception is raised if more than one event of the same type is added. Also note that the <code>this</code> refers to <code>window</code> rather than the bound element in event functions (so is less useful):<P> <strong>Attach</strong>: <code>elm.attachEvent(sEvent, fpNotify)</code><BR> <strong>Detach</strong>: <code>elm.detachEvent(sEvent, fpNotify)</code><BR> (<code>sEvent</code> is e.g. <code>'onmouseover'</code>)<P></p></li> </ul></li> <li><p><strong>Event attribute differences:</strong></p> <ul> <li><p><strong>Stop events from being processed by any other listening functions</strong>:<P> <strong>Firefox:</strong> <code>evt.stopPropagation()</code><BR> <strong>IE:</strong> <code>evt.cancelBubble = true</code></p></li> <li><p><strong>Stop e.g. key events from inserting characters or stopping checkboxes from getting checked:</strong><P> <strong>Firefox:</strong> <code>evt.preventDefault()</code><BR> <strong>IE:</strong> <code>evt.returnValue = false</code><BR> <strong>Note:</strong> Just returning <code>false</code> in <code>keydown</code>, <code>keypress</code>, <code>mousedown</code>, <code>mouseup</code>, <code>click</code> and <code>reset</code> will also prevent default.</p></li> <li><p><strong>Get the element which triggered the event:</strong><P> <strong>Firefox:</strong> <code>evt.target</code><BR> <strong>IE:</strong> <code>evt.srcElement</code></p></li> <li><p><strong>Getting the element the mouse cursor moved away from:</strong> <code>evt.fromElement</code> in IE is <code>evt.target</code> in Firefox if in an <code>onmouseout</code> event, otherwise <code>evt.relatedTarget</code></p></li> <li><p><strong>Getting the element the mouse cursor moved to:</strong> <code>evt.toElement</code> in IE is <code>evt.relatedTarget</code> in Firefox if in an <code>onmouseout</code> event, otherwise <code>evt.target</code></p></li> <li><p><strong>Note:</strong> <code>evt.currentTarget</code> (the element to which the event was bound) has no equivalent in IE.</p></li> </ul></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload