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(na me);
}
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:switch Text('one' );" style='cursor:pointer'>
<img src='img1.jpg'>
</a>
<a onclick="javascript:switch Text('two' );" style='cursor:pointer'>
<img src='img1.jpg'>
</a>
<a onclick="javascript:switch Text('thre e');" style='cursor:pointer'>
<img src='img1.jpg'>
</a>
<a onclick="javascript:switch Text('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
<script language="javascript">
function returnObj(name)
{
var obj = null;
if(document.all)
{
obj = document.all[name];
}
else if(document.getElementById
{
obj = document.getElementById(na
}
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:switch
<img src='img1.jpg'>
</a>
<a onclick="javascript:switch
<img src='img1.jpg'>
</a>
<a onclick="javascript:switch
<img src='img1.jpg'>
</a>
<a onclick="javascript:switch
<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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER