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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Whitespace in FireFox 2

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Can anyone give me a heads up on how firefox deals with white space.

I wrote a css/javascript DHTML menu, it worked like a dream in I.E., yet nothing appeared in FF.

However, all I did to fix the problem was remove the whitespace between the tags (the code was built dynamically with PERL).

It now works fine in both I.E & FF.

I have to conclude that there is an issue/difference in how FF deals with whitespace.

I'm not sure why FF couldn't handle the whitespace in the code, and would like some pointers for reference, so i don't waste another day chacing bugs in my code that aren't there.

Regards,

1DMF.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Hello Dan,

Here you go (Both work in IE)

1. this doesn't work in FF
2. this does work in FF
I have commented the 2nd example to show all I have done is remove whitespace.

Any idea why this is happening?



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
I just did a quick look at the problem area (odd indeed).

There appears to be an extra </li> in there just before the last </ul>

Maybe that has something to do with it - because I can't see any illegal characters etc.

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]

What is Javascript? faq216-6094
 
I just removed it and tested, same result - yes very odd!

As you have seen yourself, there nothing different between the two html files except whitespace!

Oh well at least I know to watch for this in future if i want my page to work in FireFox.



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
oh sorry - i removed them - thought you had already done your viewing - they're back up now !

you can also see why i was interested in the cross domain DHTML DOM issue, i'd like to have the Iframe update the "Viewing Statement......" bit, so opted for the timeout on the parent page.

don't suppose you have any insight into how I might better do this. is there a way to check if the iframe has loaded and then update.

can I get the url source of the iframe and do a comparison, with an interval time setting? and if it has changed update the innerHTML of the div tag ?

would that be an idea?



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Aaah - I see what is happening - it's a JavaScript error related to whitespace.

I should apologies - when I said earlier "I've never heard of Firefox breaking due to whitespace" - I assumed you mean that the HTML was not rendering correctly. I should have asked if you meant HTML or JS.

The JS is breaking because you are assuming "firstChild" is always an element node - when it can, in fact, be a whitespace node. You should ALWAYS test the "nodeType" property before making such assumptions.

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
wow - i'm glad that makes sense to you. I didn't write the JS, I erm "borrowed" it ;-)

So the DOM creates nodes for white space in FF but not in I.E. or is I.E ignoring the JS error?

I don't get an error in IE or FF, are there different types of JS errors, those that pop that little window up and those that don't show any signs of an error and just carry on?

I know FF is very tetchy over CSS or JS errors, one error and it completely halts (and doesn't even show an error in the status bar or popup). where as I.E. will carry on trying to process after an error, indicating an error in the status bar.

I thought it might have been to do with the JS stuff, always hard to track these down when you didn't write the code and don't understand it enough, I think they also wrote it deliberatley in an ugly fashion to stop you using it - didn't work though :)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Ahhh... the old "blank text node for FF/NN/Moz" answer [smile] I remember seeing that when doing some parsing of the DOM in another project and not understanding where these extra nodes were coming from. Thanks for pointing it out, Dan... I won't forget again :)

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]

What is Javascript? faq216-6094
 
I don't get an error in IE or FF

Odd - as soon as I load the non-working one, my Firefox JS console has the error appear in it. Odd?!

So the DOM creates nodes for white space in FF but not in I.E. or is I.E ignoring the JS error?

I'm not entirely sure about how whitespace is parsed by each browser, but know that I've certainly run into this issue before. It's just one of those things to file away for a rainy day (which is fairly often here ;o)

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Glad you guys knew about this (bug) or should I say "behaviour"!

As for the JS error i must have something turned off in my FF settings regarding JS errors, i'll look into it.

bit of a nightmare though, whitespace enables you to correctly format your code in a nice readable layout.

Helps you to line up start and end tags, loops etc. common programming practice.

but yep now I know, writing JS if it works in I.E and not FF look out for those pesky whitespaces [ghost] [ghost] [ghost] ...oooohhhhh... [ghost] [ghost] [ghost] there's a ghost roaming my browser!!!!!

any thoughts on my other question regarding the update of the parent innerHTML?





"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
any thoughts on my other question regarding the update of the parent innerHTML?
Not really. We have a similar issue here and solved it by moving the 3rd party to use one of our sub domains (hence the question earlier about whether that was possible for you). I think the setTimeout solution is the next best option at this stage.

One obscure thing to note - innerHTML won't work on Opera 6 for Windows or NN4 (but it works on pretty much everything else). Just so you know :)

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]

What is Javascript? faq216-6094
 
god damn it, does anything work on every browser!!!

I read that NN latest version only just adopted it as it is actually an MS invention.

Can you advise me on another way of changing the HTML content of a node and have the browser re-render it in real time?

regards,

1DMF.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
bit of a nightmare though, whitespace enables you to correctly format your code in a nice readable layout.

There's absolutely nothing wrong with having nicely formatted code with whitespace in - you just need to make sure that your (or in this case, someone elses) JavaScript is written well enough to cope with it.

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
lol Dan, point taken :p

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
I read that NN latest version only just adopted it as it is actually an MS invention.
You played right into my hands on this one (I researched it a few months back for someone)...

It was indeed initially a MS proposed "standard" and was so useful that it was adopted by everyone else. Netscape has had innerHTML support since Netscape 6.0PR2 (which was some time in mid-May 2000). Opera has had full support since about the same time.

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]

What is Javascript? faq216-6094
 
I read a post somewhere a week or so ago, not sure where it was, but you are probably right, the post must have been quite old, so when they said latest, it probably wasn't the latest V8.

but funnily enough, it made me decide to bite the bullet and download NS V8 as currently I only test with I.E & FF, and guess what the download/install link does on the NetScape Browser page.


lol - dunno about my code not being fully cross browser compatible, my PC says the WinXP NS V8 install isn't Windows compatible. you have to chuckle!



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Hehe... check out Opera (they just rev'd to 8.51 now) for a different experience. It's simple to remove it without any side-effects if you decide it's a waste of time... but I find it comforting to pass my code through Opera before checking it in for others to use.

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]

What is Javascript? faq216-6094
 
Guess what I just did, wow is it me or is Opera FAST!!!!!

However I've found a display issue with it, what part of height="100%" doesn't opera understand?


view that in opera the right hand iframe should be 100% in height, why isn't it?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top