IE, Opera, Netscape, & Mozilla

  • Thread starter jfancy-Transport Canada
  • Start date
J

jfancy-Transport Canada

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...?
 
D

Daniel Kirsch

jfancy-Transport Canada said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top