Jump to content

Works In Opera, Not Firefox. Looking For A Work Around.


sythem
 Share

Recommended Posts

So I've got an interesting problem that I do believe is the fault of the firefox javascript engine but I figure there has to be a way around it.

var b = new Array();	b = a.split("&");	console.log(b);	for ( x in b ) {what needs to be done}

In firefox using firebug, I can see that b contains exactly what I want it to. In opera, it does exactly what I want it to when the console.log(B); is commented out. However, in firefox, it always does everything correct for the first 2 parts, most of the time get's the 3rd pass, and rarely get's the 4th pass. What other ways are there to call a bit of script for each part of the string split by &? My site already doesn't disply right in IE, which I plan on fixing later, so I really need it to work right now in firefox otherwise I'll be limited to Opera being the only browser that renders it correctly. Which leaves me wonderiing, if Opera can render things correctly, why can't the two giants IE and Firefox?Looking forward to an answer!Thanks in advance!

Edited by sythem
Link to comment
Share on other sites

The problem is that when accessing x in b, you're accessing all the array elements, as well as all its properties and methods such as length, prototype, constructor ...

Link to comment
Share on other sites

There's nothing wrong with that code, your problem is whatever you have in the for loop
There's nothing wrong with any of my code, I've constantly put it through firebug and I keep it clean to the point of not even having warnings. It's all spotless and complies with everything I've seen on W3schools, hence the reason the javascript itself works fine in opera and IE, just formatting doesn't quite work in IE.
The problem is that when accessing x in b, you're accessing all the array elements, as well as all its properties and methods such as length, prototype, constructor ...
Can you purpose a work around for this in firefox? IE and Opera must not perform it that way.
Link to comment
Share on other sites

It's all spotless and complies with everything I've seen on W3schools
Well, if you say so. But this:
it always does everything correct for the first 2 parts, most of the time get's the 3rd pass, and rarely get's the 4th pass
Sounds like there's something wrong with the code or how you're using the elements. But hey, if you don't want us to look at the code and check for problems that's your call.
Link to comment
Share on other sites

Why don't you just use a normal for loop:for (i=0; i < b.length; i++) { code } ?

Link to comment
Share on other sites

You're not getting it. Firefox handles for(x in object) JUST FINE. We use it all the time. I happen to be using it today. FINE. FINE. FINE. It could be that the code in your {} loop does something incorrectly. This could happen, for example, if your array object has been re-prototyped (like if you're using the Prototype library) or if it contains members that the loop cannot handle for some reason. (Like if one of the members is a Number and you're trying to call a String method on it.)Here's a general rule that applies in 2009. If there is a disagreement between Firefox and any other browser, Firefox is almost certainly doing it correctly, and the other one is not. Get used to that idea. It's the reason most of us test our code in Firefox FIRST, even if Firefox is not our favorite browser.If you want more help, you should post the code that's in the {} loop. Telling us more about the array itself could be helpful, too. Also if you are using a library that might be re-prototyping things. The Prototype Library, for example, tells you specifically NOT to use for(x in object). (I don't know about jQuery.)FWIW, Ingolme is partially incorrect (a very unusual phenomenon). for(x in object) iterates right past native members of objects and accesses only those that the script has explicitly assigned.

Link to comment
Share on other sites

Why don't you just use a normal for loop:for (i=0; i < b.length; i++) { code } ?
I wish I could, but the size of the array changes depending on the part of the website you're on.Sorry about not posting the code. Here it is.
function hashtoxml () {	var a = new String(location.hash);	a = a.slice(1);	var b = new Array();	b = a.split("&");	for ( x in b ) {		if (!windowlist[b[x]]) {			if ( b[x] != "" && b[x].slice(b[x].length-2) != "_c") {				windowlist[b[x]] = new windowObj(b[x]);			}		}		if (b[x].slice(b[x].length-2) == "_c") {			contentcall(b[x]);		}	}}

No prototyping is done anywhere in the code. The specific error I'm getting from Firefox when it doesn't work is b[x] is undefined. What it does is get's the hash location from the address bar, cuts off the # character, then splits it at every & character into array elements. Then it takes each element and uses it's info to create my windowObj declared else where in the code, or in the other case calls contentcall to fill a div within a pre-existing window. In the case of my problem, contentcall is not used. Printing b shows that b always contains exactly what's needed, but it still errors.

Edited by sythem
Link to comment
Share on other sites

You're not getting it. Firefox handles for(x in object) JUST FINE. We use it all the time. I happen to be using it today. FINE. FINE. FINE. .
Didn't mean to touch on a nerve :). Also another general rule is that if something works two places but not the other, it's generally something to do with the other. Supported also by the fact that firefoxes behavior changes on reloads of the page... I'm sorry I went with my gut instead of bowing down to praise the flawless firefox.
Link to comment
Share on other sites

In addition to printing b, also print x to see what it's trying to grab. It will be helpful to know specifically what it's looking for when the error happens. The contents of windowlist might also be helpful to know. Also, if the length of b[x] is less than 2, the slice method is going to have a problem.

praise the flawless firefox
You certainly don't waste any time calling your own code flawless though. Sorry, "spotless".
Link to comment
Share on other sites

In addition to printing b, also print x to see what it's trying to grab. It will be helpful to know specifically what it's looking for when the error happens. The contents of windowlist might also be helpful to know. Also, if the length of b[x] is less than 2, the slice method is going to have a problem.You certainly don't waste any time calling your own code flawless though. Sorry, "spotless".
Thank you for you help!!! You just pointed me to exactly what was going on. And to be fair, it wasn't an error. Some how between the first if statment and the 2nd one, but only on the 2nd or 3rd passes, never on the first, b[x] manages to become undefined in firefox. Adding an "else" before this if statement keeps this behavior from causing an error allowing the code to finish properly.Thanks again justsomeguy.
Link to comment
Share on other sites

I wish I could, but the size of the array changes depending on the part of the website you're on.
Using a for loop like that, it doesn't matter how many items there are in the array, because b.length holds that value, regardless of how long the array is, and the condition i < b.length makes sure that it won't try to find elements that aren't there.
Link to comment
Share on other sites

OK - now that this is solved, we can all settle down and learn a few things, aside from javascript.Its been a while since we've had a conversation borderline on being healthy, so I'm not taking any "action" but sending a friendly reminder to keep it respectful. Remember this community is made up of a very diverse group of people - in every aspect of the word, most notable age and experience. Whether your posting or replying, lets keep our egos in check, please.@sythem - if you only tell people you've got alot of blood on you and fail to tell them how it happened, no one can really be of any help to you. You can scream at the top of your lungs, "its not my blood" but until its been proven it will be assume that it is - for your own good.@Deirdre's Dad - I understand you and I know you've had some pretty abrasive replies (from a certain perspective) in the past. I'm just asking you to keep in mind that many of the commonsensical things you and even I may think exist, often do not. Pull it in a little, please. :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...