views:

20

answers:

2

Here is my problem : when i call document.defaultView.getComputedStyle(Node, "").getPropertyValue("line-height")

safari returns the string "normal" when no line-height is specified, whereas firefox always returns the value in pixels.

This poses me a big problem, especilly because I didn't found a reliable formula to get the numeric value (I found it should be between 1em and 1.3 but nothing precise).

Is there a solution?

A: 

No, there is no solution. The defaults will always differ between browsers, as there is no standard for what the defaults should be.

Users can set their own style sheet to override the standards, so you can even get different result from two different instances of the same browser.

Guffa
A: 

Well I found a partial solution :

function getLineHeight(node){
        var clh=document.defaultView.getComputedStyle(node, "").getPropertyValue("line-height");
        var copy;
        if (clh=="normal"){

            copy=node.cloneNode(false);
            copy.style.padding=0+"px";
            copy.style.border="none";
            copy.innerHTML="x <br> x <br> x <br> x <br> x <br> x <br> x <br> x <br> x <br> x";
            node.parentNode.insertBefore(copy, node);
            clh=copy.offsetHeight/10;
            node.parentNode.removeChild(copy);
            delete copy;
        }
        else clh=parseFloat(clh);
        return clh;
    } 

For those that are wondering why all those "br" in the "innerHTML" well offsetHeight returns integer values, so using a 10 line node and dividing the result by 10 gives more accurate answer.

Cons