Firefox removing spaces from my javascript strings

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • starsky51@gmail.com

    #1

    Firefox removing spaces from my javascript strings

    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="javas cript" type="text/javascript">
    alert('First String Second String');
    </script>
    </head>
    <body>
    <form id=main name=main onsubmit="retur n false;">
    <table>
    <tr><td colspan=2><inpu t 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.

  • McKirahan

    #2
    Re: Firefox removing spaces from my javascript strings

    <starsky51@gmai l.comwrote in message
    news:1159881866 .518963.78610@m 7g2000cwm.googl egroups.com...
    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="javas cript" type="text/javascript">
    alert('First String Second String');
    </script>
    </head>
    <body>
    <form id=main name=main onsubmit="retur n false;">
    <table>
    <tr><td colspan=2><inpu t 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');


    Comment

    • starsky51@gmail.com

      #3
      Re: Firefox removing spaces from my javascript strings


      McKirahan wrote:
      >
      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!

      Comment

      • Matt Kruse

        #4
        Re: Firefox removing spaces from my javascript strings

        starsky51@gmail .com wrote:
        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?

        --
        Matt Kruse




        Comment

        • Martin Honnen

          #5
          Re: Firefox removing spaces from my javascript strings



          starsky51@gmail .com wrote:

          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.

          --

          Martin Honnen
          http://JavaScript.FAQTs.com/

          Comment

          • Dr John Stockton

            #6
            Re: Firefox removing spaces from my javascript strings

            JRS: In article <45228bdc$0$173 94$9b4e6d93@new sspool2.arcor-online.net>,
            dated Tue, 3 Oct 2006 18:12:10 remote, seen in
            news:comp.lang. javascript, Martin Honnen <mahotrash@yaho o.deposted :
            >starsky51@gmai l.com wrote:
            >
            >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.
            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?

            --
            © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
            <URL:http://www.jibbering.c om/faq/>? JL/RC: FAQ of news:comp.lang. javascript
            <URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
            <URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.

            Comment

            • starsky51@gmail.com

              #7
              Re: Firefox removing spaces from my javascript strings

              Martin Honnen wrote:
              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="javas cript" type="text/javascript">
              document.getEle mentById('maill ink').textConte nt=
              '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.

              Comment

              • Matt Kruse

                #8
                Re: Firefox removing spaces from my javascript strings

                starsky51@gmail .com wrote:
                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.getEle mentById('maill ink').textConte nt=
                '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.

                --
                Matt Kruse




                Comment

                • starsky51@gmail.com

                  #9
                  Re: Firefox removing spaces from my javascript strings


                  Matt Kruse wrote:
                  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.
                  >
                  I am using 1.5.0.7.
                  >
                  The alert problem, at least, seems to be fixed in version 2.0rc1.
                  Thanks for your help.

                  Dave.

                  Comment

                  Working...