diff --git a/src/dom/DomElement.js b/src/dom/DomElement.js index 60d665c4..c8f5c8c2 100644 --- a/src/dom/DomElement.js +++ b/src/dom/DomElement.js @@ -140,11 +140,19 @@ var DomElement = new function() { }, getBounds: function(el, viewport) { - var rect = el.getBoundingClientRect(), - doc = el.ownerDocument, + var doc = el.ownerDocument, body = doc.body, html = doc.documentElement, - x = rect.left - (html.clientLeft || body.clientLeft || 0), + rect; + try { + // On IE, for nodes that are not inside the DOM, this throws an + // exception. Emulate the behavior of all other browsers, which + // return a rectangle of 0 dimensions. + rect = el.getBoundingClientRect(); + } catch(e) { + rect = { left: 0, top: 0, width: 0, height: 0 }; + } + var x = rect.left - (html.clientLeft || body.clientLeft || 0), y = rect.top - (html.clientTop || body.clientTop || 0); if (!viewport) { var view = doc.defaultView;