IE, Opera, Netscape, & Mozilla

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jfancy-Transport Canada

    #1

    IE, Opera, Netscape, & Mozilla

    This code needs to be changed so that it is compatible with other
    browsers like Opera, Netscape, and Mozilla.

    {
    s=a[i].currentStyle.f ontSize+'';
    s=Right(s,2);
    a[i].style.fontSize = parseInt(a[i].currentStyle.f ontSize)+factor +s;
    }


    In particular, the "currentSty le" and "style" i would imagine needs to
    be changed to something and i'm not sure how to go about doing that.

    Any Suggestions...?

  • Daniel Kirsch

    #2
    Re: IE, Opera, Netscape, & Mozilla

    jfancy-Transport Canada wrote:[color=blue]
    > This code needs to be changed so that it is compatible with other
    > browsers like Opera, Netscape, and Mozilla.
    >
    > {
    > s=a[i].currentStyle.f ontSize+'';
    > s=Right(s,2);
    > a[i].style.fontSize = parseInt(a[i].currentStyle.f ontSize)+factor +s;
    > }
    >
    >
    > In particular, the "currentSty le" and "style" i would imagine needs to
    > be changed to something and i'm not sure how to go about doing that.
    >
    > Any Suggestions...?[/color]

    I use a function to get a defined style of an element:

    function getStyle(aElm, aStyle) {
    var lStyle;
    try {
    if (aElm && typeof aElm.style != "undefined" )
    lStyle = aElm.style[aStyle];
    }
    catch(e) {}

    var retVal;

    if (lStyle)
    retVal = lStyle;
    else {
    // Mozilla
    if (document.defau ltView) {
    aStyle = aStyle.replace(/([A-Z])/g, "-$1").toLowerCas e();
    retVal =
    aElm.ownerDocum ent.defaultView .getComputedSty le(aElm,"").get PropertyValue(a Style);

    // some elements might not have a defined value (eg. images)
    if (retVal == "auto") {
    if (aStyle == "width")
    retVal = aElm.offsetWidt h;
    else if (aStyle == "height")
    retVal = aElm.offsetHeig ht;
    }
    }
    // IE
    else if (aElm.currentSt yle) {
    retVal = aElm.currentSty le[aStyle];
    }
    else
    return null;
    }
    return retVal;
    }

    Your script block might then look like this (note, I don't know what
    "Right" does and "factor" is so if you don't get it working, you might
    show us some more code):

    s = getStyle(a[i],"fontSize") ;
    var s_new=Right(s,2 );
    a[i].style.fontSize = parseInt(s)+fac tor+s_new;

    Daniel

    Comment

    Working...