Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   IE, Opera, Netscape, & Mozilla (http://www.velocityreviews.com/forums/t918385-ie-opera-netscape-and-mozilla.html)

jfancy-Transport Canada 05-31-2005 01:52 PM

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.fontSize+'';
s=Right(s,2);
a[i].style.fontSize = parseInt(a[i].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...?


Daniel Kirsch 06-01-2005 07:30 AM

Re: IE, Opera, Netscape, & Mozilla
 
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[i].currentStyle.fontSize+'';
> s=Right(s,2);
> a[i].style.fontSize = parseInt(a[i].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(aE lm,"").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[i],"fontSize");
var s_new=Right(s,2);
a[i].style.fontSize = parseInt(s)+factor+s_new;

Daniel


All times are GMT. The time now is 09:45 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.