Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
javascript works in IE but not firefox
Old 05-05-2006, 01:12 AM javascript works in IE but not firefox
hodgezz's Avatar
Novice Talker

Posts: 5
Trades: 0
i am having problems with a simple imageswapping function - it works right in ie but not in firefox. here is part of my code and the firefox error which is displayed. i figure that i should be checking for firefox browser as well, but i have other stuff that does work and didn't have to do a browser check. thanks in advance



browserName = navigator.appName;
browserVer = parseInt(navigator.appVersion);
if (browserName == "Netscape" && browserVer >= 3) browserVer = "1";
else if (browserName == "Microsoft Internet Explorer" && browserVer == 4) browserVer = "1";
else browserVer = "2";


//image loading function used on photo pages
function load_pics(num_pics, fold_name){
for (i=1; i <=num_pics; i++)
{
photo[i] = new Image(); LINE 50
photo[i].src = fold_name + "pic" + i + ".jpg";
}
}
//image swapping function:
function image_swap(image_id, image_name) {
if (browserVer == 1) {
document.images[image_id].src = eval(image_name + ".src"); LINE 57
return true;

}}


Error: photo is not defined
Source File: XXXX(i changed this)
Line: 50

Error: photo is not defined
Source File: XXXXLine: 57

Last edited by hodgezz; 05-11-2006 at 03:16 PM..
hodgezz is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-05-2006, 01:13 AM Re: javascript works in IE but not firefox
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
Put this line at the very beginning of your Javascript:

var photo = new Array();

This will declare the variable "photo" as an array regardless of browser.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 05-05-2006, 01:24 AM Re: javascript works in IE but not firefox
hodgezz's Avatar
Novice Talker

Posts: 5
Trades: 0
thanks. i tried that before though, and nothing will work though. i get an "Object Expected" error. any idea? i am pretty sure that it is the array causing problems, because i have other images being swapped, but i preloaded them with the actual paths.

Last edited by hodgezz; 05-05-2006 at 01:31 AM..
hodgezz is offline
Reply With Quote
View Public Profile
 
Old 05-05-2006, 02:06 AM Re: javascript works in IE but not firefox
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
What's the page itself look like?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 05-05-2006, 02:39 AM Re: javascript works in IE but not firefox
hodgezz's Avatar
Novice Talker

Posts: 5
Trades: 0
the part the code is for i just a table (2 col & 1 row) on the left side is a large picture, on the right side is number of thumbnails. whenever you mouseover one of the smaller ones it shows a large version of it on the picture on the right.
hodgezz is offline
Reply With Quote
View Public Profile
 
Old 05-05-2006, 10:14 AM Re: javascript works in IE but not firefox
Nikko's Avatar
Novice Talker

Posts: 9
Location: Norway
Trades: 0
It would help more if you could give us the rest of the code, but I think the bug (or at least, one of them) is that you're using document.images[..], which is not allowed in firefox (pretty sure, but not 100%) [edit:I was wrong. document.images is allowed in firefox too]. Use document.getElementById(..) instead.

Don't forget to add

photo[i].id = groupname + "_" + i;

or something similar.

Btw. are you sure that it's executed? Like, if (browserVer == 1) {. I wouldn't be too sure browserVer == 1 in firefox..?

Also, have you written this code yourself?

Last edited by Nikko; 05-05-2006 at 11:03 AM..
Nikko is offline
Reply With Quote
View Public Profile
 
Old 05-05-2006, 08:09 PM Re: javascript works in IE but not firefox
hodgezz's Avatar
Novice Talker

Posts: 5
Trades: 0
the browser stuff i got from a turorial, the rest i was able to come up with. at the bottom(in blue) are the lines of code where i actually call the functions in. well, here is all of the code in my javascript file:

//var photo = new Array();

//detect browser:
browserName = navigator.appName;
browserVer = parseInt(navigator.appVersion);
if (browserName == "Netscape" && browserVer >= 3) browserVer = "1";
else if (browserName == "Microsoft Internet Explorer" && browserVer == 4) browserVer = "1";
else browserVer = "2";
//preload all the images :
if (browserVer == 1) {
default_image = new Image()
default_image.src = "main_menu/select_home.jpg"
select_home = new Image();
select_home.src = "main_menu/select_home.jpg";

Last edited by hodgezz; 05-11-2006 at 03:16 PM..
hodgezz is offline
Reply With Quote
View Public Profile
 
Old 05-11-2006, 03:13 PM Re: javascript works in IE but not firefox
hodgezz's Avatar
Novice Talker

Posts: 5
Trades: 0
i got the pages to work right, but it is not really a "good" fix. IE is having problrms with the photo = new Array(num_pics); , but netscape and firefox(whose browsername is "netscape" for some reason) need it in order to work. does anyone know why IE would be having a problem with it? here is the function that is working. thanks in advance...


function load_pics(num_pics, fold_name){

if (browserName == "Netscape") photo = new Array(num_pics);

for (i=1; i <=num_pics; i++)
{
photo[i] = new Image();
photo[i].src = fold_name + "pic" + i + ".jpg";
}
}
hodgezz is offline
Reply With Quote
View Public Profile
 
Old 05-16-2006, 11:46 AM Re: javascript works in IE but not firefox
Extreme Talker

Posts: 161
Location: Netherlands
Trades: 2
Instead of:
if (browserName == "Netscape")

You might wanne use:
if(!document.all)
__________________
Visit the
Please login or register to view this content. Registration is FREE
.
Add cool effects to your images, and even create your own animated gif's!
Skorpija is offline
Reply With Quote
View Public Profile Visit Skorpija's homepage!
 
Reply     « Reply to javascript works in IE but not firefox
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31139 seconds with 12 queries