Firefox removing spaces from my javascript strings

S

starsky51

I'm sure it's something i'm doing wrong, I just can't see it.
I've set up a simple page with the following code:

<html>
<head>
<title>tester</title>
<script language="javascript" type="text/javascript">
alert('First String Second String');
</script>
</head>
<body>
<form id=main name=main onsubmit="return false;">
<table>
<tr><td colspan=2><input type=submit></td></tr>
</table>
</form>
<div id=maillink></div>
</body>
</html>

Opening this in IE pops up 'First String Second String',
as expected.
Firefox converts the multiple spaces into a single space giving: 'First
String Second String'

Can anyone tell me a way of getting Firefox to display the extra
spaces?

TIA,
Dave.
 
M

McKirahan

I'm sure it's something i'm doing wrong, I just can't see it.
I've set up a simple page with the following code:

<html>
<head>
<title>tester</title>
<script language="javascript" type="text/javascript">
alert('First String Second String');
</script>
</head>
<body>
<form id=main name=main onsubmit="return false;">
<table>
<tr><td colspan=2><input type=submit></td></tr>
</table>
</form>
<div id=maillink></div>
</body>
</html>

Opening this in IE pops up 'First String Second String',
as expected.
Firefox converts the multiple spaces into a single space giving: 'First
String Second String'

Can anyone tell me a way of getting Firefox to display the extra
spaces?

Try inserting a tab (\t):

alert('First String \t Second String');
 
M

Matt Kruse

alert('First String Second String');
Firefox converts the multiple spaces into a single space giving:
'First String Second String'

It doesn't for me. Can you provide an actual test url and tell us exactly
which version of FF you are using?
 
S

starsky51

McKirahan said:
Try inserting a tab (\t):

alert('First String \t Second String');

Thanks for the response.
The \t didn't work.
But using the escape slash gave me an idea. Using \u00A0 gives a
non-breaking space.
This seems to do the trick, but isn't ideal. I would still appreciate
any suggestions anyone may have!
 
M

Martin Honnen

alert('First String Second String');

Firefox converts the multiple spaces into a single space giving: 'First
String Second String'

That is a known bug with the alert dialog in Firefox, the spaces are
there in the string itself but the alert dialog collapses them when
displaying the string.
 
D

Dr John Stockton

JRS: In article <[email protected]>,
dated Tue, 3 Oct 2006 18:12:10 remote, seen in
news:comp.lang.javascript said:
That is a known bug with the alert dialog in Firefox, the spaces are
there in the string itself but the alert dialog collapses them when
displaying the string.

If really necessary, maybe the string can be written to a new window.

Alternatively, as \u00A0 works, one might, if it works everywhere else,
use

function alert(S) { window.alert(S.replace(/ /g, " \u00A0")) }

Do I need to do that on my own site?
 
S

starsky51

Martin said:
That is a known bug with the alert dialog in Firefox, the spaces are
there in the string itself but the alert dialog collapses them when
displaying the string.

This isn't just happening in the alert dialogs, that was just an
example. Firefox seems to be collapsing all of my strings:

Here is an example using textContent
(http://starsky51.googlepages.com/testtemp.htm):
<html>
<body>
<div id=maillink></div>
<script language="javascript" type="text/javascript">
document.getElementById('maillink').textContent=
'First String Second String';
</script>
</body>
</html>

I am using 1.5.0.7. If no one else can replicate the problem then I'll
have to check my extensions. I've disabled GreaseMonkey, just in case
it was that, but no change.
 
M

Matt Kruse

This isn't just happening in the alert dialogs, that was just an
example. Firefox seems to be collapsing all of my strings:
Here is an example using textContent
document.getElementById('maillink').textContent=
'First String Second String';

This is to be expected, since whitespace in html documents is compressed
into a single space.

<div>First String Second String</div>

should never display all the spaces in any browser.
I am using 1.5.0.7.

The alert problem, at least, seems to be fixed in version 2.0rc1.
 
S

starsky51

Matt said:
This is to be expected, since whitespace in html documents is compressed
into a single space.

<div>First String Second String</div>

should never display all the spaces in any browser.

Ah didn't think of it like that, thanks.
The alert problem, at least, seems to be fixed in version 2.0rc1.

Thanks for your help.

Dave.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top