Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JavaScripts in Firefox

Status
Not open for further replies.

coxellis

Programmer
Jan 21, 2003
10
GB
I'm running a script on my website at which loads thumbnails from an array into anchors. It works fine in ie but doesn't work in Firefox - anyone know why?

Cheers :)

Andy

Array:

mypicarray = new Array("M81 - Bodes Galaxy","SkyWatcher 200, Hx916","L - 2 mins binned 1x1, RG - 1 min binned 2x2, B - 70 secs binned 2x2","images/hx916/dso/m81.jpg","images/hx916/dso/thumbs/m81thumb.jpg","M82 - Cigar Galaxy","SkyWatcher 200, Hx916","L - 3 mins binned 1x1, RGB - 2 mins binned 2x2","images/hx916/dso/m82.jpg","images/hx916/dso/thumbs/m82thumb.jpg","M63 - Sunflower Galaxy","SkyWatcher 200, Hx916","L - 3 mins binned 1x1, RGB - 2 mins binned 2x2","images/hx916/dso/m63final.jpg","images/hx916/dso/thumbs/m63finalthumb.jpg","M3 - Globular Cluster","SkyWatcher 200, Hx916","","images/hx916/dso/m3.jpg","images/hx916/dso/thumbs/m3thumb.jpg","M108 - Galaxy","SkyWatcher 200, Hx916","L - 3 mins binned 1x1, RGB - 2 mins binned 2x2","images/hx916/dso/m108.jpg","images/hx916/dso/thumbs/m108thumb.jpg","Christmas Tree Cluster and Cone Nebula","SkyWatcher ST102, Hx916","Ha - 10min, 20min subs, GB - 1 min binned 2x2","images/hx916/dso/xmascone.jpg","images/hx916/dso/thumbs/xmasconethumb.jpg");

Code:

function loader()
{
for(i = 5;i<mypicarray.length + 1;i = i + 5)
{
maintitle = mypicarray[i-5];
mypic = mypicarray[i-2];
mythumb = mypicarray[i-1];
imgstr = "<img src='" + mythumb + "' width=200 alt='" + maintitle + "' border=0 onClick='javascript:gopic(" + (i-2) + ")'>";
eval("andy" + (i/5) + ".innerHTML = \"" + imgstr + "\";");
}
return;
}

function gopic(mypic)
{
window.location.href = "pic.htm?mypic=" + mypic;
return;
}

HTML:

<a name="andy1"></a>&nbsp;<a name="andy2"></a>&nbsp;<a name="andy3"></a><br> (etc...)
 
Let's clean this up a bit, quick and dirty:

Code:
function PicObj(maintitle, subtitle, description, mypic, mythumb)
{
this.maintitle=maintitle;
this.subtitle=subtitle;
this.description=description;
this.mypic=mypic;
this.mythumb=mythumb;
return this;
}

mypicarray = new Array(), mi=0;

mypicarray[mi++]=new PicObj("M81 - Bodes Galaxy", "SkyWatcher 200, Hx916", "L - 2 mins binned 1x1, RG - 1 min binned 2x2, B - 70 secs binned 2x2", "images/hx916/dso/m81.jpg", "images/hx916/dso/thumbs/m81thumb.jpg");

mypicarray[mi++]=new PicObj("M82 - Cigar Galaxy", "SkyWatcher 200, Hx916", "L - 3 mins binned 1x1, RGB - 2 mins binned 2x2", "images/hx916/dso/m82.jpg", "images/hx916/dso/thumbs/m82thumb.jpg");

mypicarray[mi++]=new PicObj("M63 - Sunflower Galaxy", "SkyWatcher 200, Hx916", "L - 3 mins binned 1x1, RGB - 2 mins binned 2x2", "images/hx916/dso/m63final.jpg", "images/hx916/dso/thumbs/m63finalthumb.jpg");

mypicarray[mi++]=new PicObj("M3 - Globular Cluster", "SkyWatcher 200, Hx916", "", "images/hx916/dso/m3.jpg", "images/hx916/dso/thumbs/m3thumb.jpg");

mypicarray[mi++]=new PicObj("M108 - Galaxy", "SkyWatcher 200, Hx916", "L - 3 mins binned 1x1, RGB - 2 mins binned 2x2", "images/hx916/dso/m108.jpg", "images/hx916/dso/thumbs/m108thumb.jpg");

mypicarray[mi++]=new PicObj("Christmas Tree Cluster and Cone Nebula", "SkyWatcher ST102, Hx916","Ha - 10min, 20min subs, GB - 1 min binned 2x2", "images/hx916/dso/xmascone.jpg", "images/hx916/dso/thumbs/xmasconethumb.jpg");


function loader()
{
for(i = 0;i<mypicarray.length;i++)
  {
  maintitle = mypicarray[i].maintitle;
  mypic = mypicarray[i].mypic;
  mythumb = mypicarray[i].mythumb;
  imgstr = '<img src="' + mythumb + '" width="200" alt="' + maintitle + '" border="0" onClick="gopic(' + i + ')">';
  document.getElementById("andy" + (i + 1)).innerHTML = imgstr;
  }
return;
}

function gopic(picnum)
{
window.location.href = "pic.htm?mypic=" + mypicarray[picnum].mypic;
return;
}
</script>


<span id="andy1"></span>&nbsp;<span id="andy2"></span>&nbsp;<span id="andy3"></span>&nbsp;<span id="andy4"></span>&nbsp;<span id="andy5"></span><br>

This method uses objects, which I think are better representations of what you're thinking than the way you had your array set up.

Also, don't use javascript inside event handlers. Just put the function call.

I didn't test this, so it might have to be polished a little.

Lee
 
This html page works fine in IE but in FireFox it says func1 is not defined. In FireFox you can open the JavaScript console under the tools menu to see JavaScript errors.

---------------------------------------------------

<HTML> <HEAD> </HEAD>
<BODY>

<SCRIPT LANGUAGE="JavaScript" >

function func1()
{
document.write("func <br>");
}

function Main(inp)
{
document.write("Testing<br>");
func1();
document.write("--END--");
}

</SCRIPT>

<form name="Form1"">
<input type="button" value="Go!" onClick="Main()">
</form>

</BODY> </HTML>


-Chris (Consultant / Software Engineer)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top