Skip to content

IE 11 may throw an exception when calling getBoundingClientRect on detached elements #75

@lynchbomb

Description

@lynchbomb

IE 11 may throw an exception when calling .getBoundingClientRect on detached elements. These elements should (according to CSSOM spec) return an object with zero for the top, bottom, left, right, width, and height properties.

http://jsfiddle.net/jonathansampson/3vqddemh/ for the excellent solution to this.

try {
  document.createElement('i').getBoundingClientRect();
} catch(e) {
  let getBoundingClientRect = Element.prototype.getBoundingClientRect;
  Element.prototype.getBoundingClientRect = () => {
    try {
      return getBoundingClientRect.call(this);
    } catch(e) {
      return { top: 0, bottom: 0, left: 0, width: 0, height: 0, right: 0 }; 
    }
  }
}

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions