IE lies about borderWidth ?! How to get the actual cost?

By default, many of you know that IE has a 2px border around the body tag. IE treats this border as outside a regular page. This basically means that the beginning of the document is actually at [borderLeftWidth, borderTopWidth].

This creates problems when doing calculations in JavaScript that require both clientXY and screenXY. Since there is a border between the two values, you need to compensate for it by adding it to borderWidth. By default, this border is 2px (unless you change the page).

However, since the body can also have a custom border (e.g. 7px solid red), you cannot just compensate by adding or subtracting 2px. Obviously, you will need to use the actual value document.body.currentStyle['borderTopWidth']. By default, this returns medium. Since the value mediummay vary in different versions of the browser, you will need to do a getPixelValue check (I used: http://blog.stchur.com/2006/09/20/converting-to-pixels-with-javascript/ ).

When performing this check mediumreturns 4px. But this is not so! The boundary of the body is actually 2px, although she speaks it medium. This made me think that IE might distinguish values ​​differently for the border of the body. But after manually setting borderWidth to medium, it fixes itself to 4px. For some reason, IE lies around the default borderWidth body.

So my question is: is there a way to get the real value of the body boundary? Or is there a way to check if the user has already set the border (so that he is no longer the default value of 2px). Performing a check with a modified border will certainly be my last resort, since IE may decide to remove the default border, thereby violating my scripts.

+3
1

, .

var b = document.body;
var first1 = b.clientHeight;
var first2 = b.clientWidth;
b.style.borderTopWidth = '0px';
b.style.borderLeftWidth = '0px';
b.style.borderTopWidth = first1 - b.clientHeight + "px";
b.style.borderLeftWidth = first2 - b.clientWidth + "px";

IE medium. - , , .

0

Source: https://habr.com/ru/post/1773995/


All Articles