IE, Opera, Netscape, & Mozilla

Discussion in 'Javascript' started by jfancy-Transport Canada, May 31, 2005.

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

    {
    s=a.currentStyle.fontSize+'';
    s=Right(s,2);
    a.style.fontSize = parseInt(a.currentStyle.fontSize)+factor+s;
    }


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

    Any Suggestions...?
    jfancy-Transport Canada, May 31, 2005
    #1
    1. Advertising

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


    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.defaultView) {
    aStyle = aStyle.replace(/([A-Z])/g, "-$1").toLowerCase();
    retVal =
    aElm.ownerDocument.defaultView.getComputedStyle(aElm,"").getPropertyValue(aStyle);

    // some elements might not have a defined value (eg. images)
    if (retVal == "auto") {
    if (aStyle == "width")
    retVal = aElm.offsetWidth;
    else if (aStyle == "height")
    retVal = aElm.offsetHeight;
    }
    }
    // IE
    else if (aElm.currentStyle) {
    retVal = aElm.currentStyle[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,"fontSize");
    var s_new=Right(s,2);
    a.style.fontSize = parseInt(s)+factor+s_new;

    Daniel
    Daniel Kirsch, Jun 1, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Davisro
    Replies:
    3
    Views:
    385
    bruce barker
    Apr 29, 2004
  2. Joe Price
    Replies:
    6
    Views:
    632
    Joe Price
    Sep 26, 2003
  3. Bob
    Replies:
    24
    Views:
    1,525
  4. Jeff
    Replies:
    3
    Views:
    1,115
  5. Asterbing
    Replies:
    5
    Views:
    109
    Thomas 'PointedEars' Lahn
    Dec 2, 2005
Loading...

Share This Page