Forum Discussion

challach's avatar
challach
New Contributor
15 years ago

How to get the fontWeight in Firefox 3.5

Hello All,



I am working on TC8.2, and testing a web application in IE and Firefox.

I used Object.currentStyle.fontWeight in IE which was working good.

Same script is not working in Firefox. I tried using style.fontWeight but there was no luck.



In web I found that getComputedStyle works for Firefox similar to currentStyle in IE. Please let me know how to use that method.

OR provide any other way to solve this problem.



Thanks in advance.

Chandra.

1 Reply

  • Hello,



    The style attributes obtained via the Object.style property contain only the attributes applied directly to the given web page element. They do not take account of the attributes inherited from the parent elements.

    To get the resulting style attributes in InternetExplorer, the Object.currentStyle property is applied. Mozilla's analogue of this property is the getComputedStyle() method. You were absolutely right.  Unlike IE, the method is available only for the window object and accepts the needed element as a parameter. The following snippet demonstrates how to use this method:





    function GetStyleObj (page, elementID)

    {

      var element, ComputedStyle;

        if (Options.Web.TreeModel == "DOM")

          {

          //Obtain the element in DOM model

          element = page.document.getElementById(elementID);

          }

          else

          {

          //Obtain the element in Tag, Tree and Hybrid models

          element = page.contentDocument.getElementById(elementID);

          }

     

         ComputedStyle = page.content.getComputedStyle(element, "");

         return ComputedStyle;

    }

            

    function main()

    {

       var resultingStyle, page;

       ....

       page = Aliases.firefox.Page("www.mysite.com")

       resultingStyle = GetStyleObj (page, 'soughtElementID')

       Log.Message("Font weight = "+resultingStyle.fontWeight);

       ...

    }