Link to home
Start Free TrialLog in
Avatar of vladimir_kalashnikov
vladimir_kalashnikov

asked on

Loading External JS File onClick not working in Firefox

I have 4 images that when clicked load an external javascript file onto the page.  Here is the code for it:

                 <script language="javascript">
                  function returnObj(name)
                  {
                        var obj = null;
                        
                        if(document.all)
                        {
                              obj = document.all[name];
                        }
                        else if(document.getElementById)
                        {
                              obj = document.getElementById(name);
                        }
                        else if(document.layers)
                        {
                              obj = document.layers[name];
                        }
                        
                        return obj;
                  }

                  function switchText(name)
                  {
                        var js = returnObj('remoteJS');

                        js.src = 'test'+name+'.js';
                  }
            </script>

            <script language='javascript' id='remoteJS'>
            </script>

            <a onclick="javascript:switchText('one');" style='cursor:pointer'>
                  <img src='img1.jpg'>
            </a>
            <a onclick="javascript:switchText('two');" style='cursor:pointer'>
                  <img src='img1.jpg'>
            </a>
            <a onclick="javascript:switchText('three');" style='cursor:pointer'>
                  <img src='img1.jpg'>
            </a>
            <a onclick="javascript:switchText('four');" style='cursor:pointer'>
                  <img src='img1.jpg'>
            </a>

In the external js files I have some alerts just to test if it works:

                 alert('test 1');


So all of this works correctly in IE, but in Firefox it does nothing.  I am wondering what the difference is.  Is this a security issue (loading from an external file)?  This is probably an easy question, but I rarely use javascript and hardly ever from an external file.  Any help would be appreciated.

- vlad
ASKER CERTIFIED SOLUTION
Avatar of Zyloch
Zyloch
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vladimir_kalashnikov
vladimir_kalashnikov

ASKER

That fixed it, thanks.