Script not working in Firefox

I've got a javascript function. The system I work with generates HTML which I can't alter. To make any alterations I need to use Javascript to make the changes once the screen has loaded as I can inject javascript into the page. This is just how it is.

This code runs once the page has loaded and it is designed to read a table and in the last column with a title of "File" it is supposed iterate through each row and change the text into a link.

function makeLinks(sPath)
{
  var da = document.all;
  var sfn = "";
  var bFirst = true;
  var sVD = "/lib/";
  var sGlobalPath = sVD + "C/Global/";
  var sUserPath = sVD + sPath;

  for(var i =0; i < da.length; i++)
  {
    if(da[i].tagName == "TD")
    {
      if(da[i].innerText == "File")
      {
        var Tbl = da[i].parentElement.parentElement.parentElement;
        var offset = da[i].cellIndex;

        for(var r = 1; r < Tbl.rows.length; r++)
        {
          sfn = Tbl.rows[r].cells[offset].innerHTML;

          if(bFirst)
          {
            Tbl.rows[r].cells[offset].innerHTML = "<a href='" + sUserPath + sfn + "' target='_new'>" + sfn + "</a>";
          }
          else
          {
            Tbl.rows[r].cells[offset].innerHTML = "<a href='" + sGlobalPath + sfn + "' target='_new'>" + sfn + "</a>";
          }
        }

        bFirst = false;
      }
    }
  }
}

Open in new window


This works great in IE but it doesn't in Firefox. Now I've read varying reports that innerText and innerHTML don't display in Firefox and plenty of pages where it does work. So, what is wrong with the above code?
LVL 25
Lee SavidgeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lee SavidgeAuthor Commented:
I changed parentElement to parentNode  and that still doesn't sort the issue out in FF
0
Lee SavidgeAuthor Commented:
Changed

var da = document.all;

Open in new window


to

var da = document.getElementsByTagName("*");

Open in new window


Still the same
0
smeghammerCommented:
Hi,

Just alter the innerText to innerHTML when you do the comparison check at line 14.

      if(da[i].innerHTML == "File")
      {
        var Tbl = da[i].parentElement.parentElement.parentElement;

Open in new window

You might also look at at an alternative here:

http://stackoverflow.com/questions/12900405/innertext-alternative-in-firefox

Cheers
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Lee SavidgeAuthor Commented:
Doh! I had already gone through the code and replaced innerText with innerHTML. I guessed I missed that one. Fixed it.

bleh! Can't see the wood for the trees!
0
smeghammerCommented:
No problem. Glad it works :-)

Cheers
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.