beita1991 / blogs

4 stars 0 forks source link

firefox 浏览器下,iframe中使用 ui-grid(<=4.0.6) getStyles() 会有报错 #2

Open beita1991 opened 7 years ago

beita1991 commented 7 years ago

firefox 浏览器下,iframe中使用 ui-grid getStyles() 会有报错 ,因为e.ownerDocument.defaultView.getComputedStyle(e, null) 返回的是null,理论上不应该返回null的, 在getStyles 方法添加如下兼容代码:

function  getStyles (elem) {
  var e = elem;
  if (typeof(e.length) !== 'undefined' && e.length) {
    e = elem[0];
  }
  if (/firefox/i.test(navigator.userAgent)){
    return e.ownerDocument.defaultView.getComputedStyle(e, null) || e.style || {};
  }

  return e.ownerDocument.defaultView.getComputedStyle(e, null);
}