0

I'm trying to understand how jQuery arrives at pixel values for IE8 when dealing with non-pixel based property values, such as margin-top: 2em, or even something like height: auto. For IE9+, getComputedStyle() can obviously provide this easily, but in the case of IE8, currentStyle does not. I am trying to arrive at a solution so I can calculate the total height of an element, including CSS height, padding, border, and margin for all browsers IE8+. I have come across the following answer, but I can't understand what is going on in the accepted answer.

Cross-browser (IE8-) getComputedStyle with Javascript?

I was wondering if anyone could explain what is going on in this code?

Joe
  • 1,117
  • 1
  • 8
  • 13

1 Answers1

0

here is a shim for computed style from WebPlatform.

if (!window.wpo) { window.wpo = {}; }
if (!wpo.utils) { wpo.utils = {}; }

wpo.utils.getComputedStyle = function(_elem, _style)
{// wpo getComputedStyle shim.
   var computedStyle;
   if (typeof _elem.currentStyle != 'undefined')
     { computedStyle = _elem.currentStyle; }
   else
     { try{computedStyle = document.defaultView.getComputedStyle(_elem, null);}catch(e){return '';} }

  return computedStyle[_style];
}
Rob Parsons
  • 839
  • 6
  • 4
  • I appreciate the answer but I don't think it addresses my main concern, which is how IE8 would be able to gain access to or calculate non-pixel values for properties, such as `margin: 2em;` or `height: auto;`. – Joe Dec 02 '14 at 21:27