formatting text in JavaScript popup boxes

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

    formatting text in JavaScript popup boxes

    We can use special characters ('\n') to add line breaks in text in
    JavaScript popup Alert boxes.

    there is also few additional special characters:

    \' single quote
    \" double quote
    \& ampersand
    \\ backslash
    \n new line
    \r carriage return
    \t tab
    \b backspace
    \f form feed

    Is there also additional characters for more reach formatting? (bold
    text, etc)? Need we put "\n" inside quotations?
    Is there some Javascript popup Alert box text formatter, to format text
    from GUI, more handy way?

  • [on]

    #2
    Re: formatting text in JavaScript popup boxes


    korund@hotmail. com wrote:[color=blue]
    > We can use special characters ('\n') to add line breaks in text in
    > JavaScript popup Alert boxes.
    >
    > there is also few additional special characters:
    >
    > \' single quote
    > \" double quote
    > \& ampersand
    > \\ backslash
    > \n new line
    > \r carriage return
    > \t tab
    > \b backspace
    > \f form feed
    >
    > Is there also additional characters for more reach formatting? (bold
    > text, etc)? Need we put "\n" inside quotations?
    > Is there some Javascript popup Alert box text formatter, to format text
    > from GUI, more handy way?[/color]

    If you want graphics either open a window, or display a HTML element on
    top of everything else on the page.

    (I myself would use the last one)

    Comment

    • korund@hotmail.com

      #3
      Re: formatting text in JavaScript popup boxes

      My question was about the JavaScript popup Alert boxes.

      <script type="text/javascript">
      alert('Text');
      </script>

      Comment

      • [on]

        #4
        Re: formatting text in JavaScript popup boxes


        kor...@hotmail. com wrote:[color=blue]
        > My question was about the JavaScript popup Alert boxes.
        >
        > <script type="text/javascript">
        > alert('Text');
        > </script>[/color]

        Right and I answerd you.

        Btw: please quote the message you're responding to.

        Comment

        • korund@hotmail.com

          #5
          Re: formatting text in JavaScript popup boxes

          > kor...@hotmail. com wrote:[color=blue][color=green]
          > > My question was about the JavaScript popup Alert boxes.
          > >
          > > <script type="text/javascript">
          > > alert('Text');
          > > </script>[/color][/color]
          [color=blue]
          > Right and I answerd you.[/color]
          [color=blue]
          > Btw: please quote the message you're responding to.[/color]
          --------------------------------------------

          We can use special characters ('\n') to add line breaks in text in
          JavaScript popup Alert boxes.
          Is there also additional characters for more reach formatting? (bold
          text, etc)? Need we put "\n" inside quotations?
          Is there some Javascript popup Alert box text formatter, to format text

          from GUI, more handy way?

          Comment

          • Thomas 'PointedEars' Lahn

            #6
            Re: formatting text in JavaScript popup boxes

            korund@hotmail. com wrote:
            [color=blue]
            > We can use special characters ('\n') to add line breaks in text in
            > JavaScript popup Alert boxes.[/color]

            True.
            [color=blue]
            > there is also few additional special characters:
            >
            > \' single quote
            > \" double quote[/color]

            Those are not special characters in any way. They are escape sequences
            required only when the escaped character already serves as a string literal
            delimiter.
            [color=blue]
            > \& ampersand[/color]

            Well, the same goes for \a, \c, \d and so on in string literals, because it
            is not a valid escape sequence. The ampersand does not need to be escaped.
            [color=blue]
            > \\ backslash[/color]

            Again, that is not a special character, but an escape sequence for the
            backslash character, which serves as escape sequence prefix itself
            (hence the requirement to escape it if the literal character is needed).
            [color=blue]
            > \n new line
            > \r carriage return
            > \t tab
            > \b backspace
            > \f form feed[/color]

            That is true, and the characters displayed by those escape
            sequences are the only special characters you mentioned.

            ECMAScript Edition 3 also defines the escape sequence

            \v (equivalent to \u000B)

            for the <VT> (Vertical Tab) character (U+000B). See ECMAScript Edition 3
            Final, subsection 7.8.4.
            [color=blue]
            > Is there also additional characters for more reach formatting? (bold
            > text, etc)?[/color]

            No.
            [color=blue]
            > Need we put "\n" inside quotations?[/color]

            I do not know if you have to; I have, as I prefer to have running code.
            \n is an escape sequence valid within (string and RegExp) literals only.
            [color=blue]
            > Is there some Javascript popup Alert box text formatter, to format text
            > from GUI, more handy way?[/color]

            No. You will have to create your own popup window. There are some
            proprietary approaches, such as showModalDialog () in the IE DOM, that
            support you in creating modal windows as you know them from window.alert():

            <URL:http://msdn.microsoft. com/workshop/author/dhtml/reference/methods/showmodaldialog .asp>

            Gecko-based UAs have window.open(... , ..., "modal") and window.openDial og():

            <URL:http://developer.mozil la.org/en/docs/DOM:window#Meth ods>

            But none of these is interoperable.

            And to save you another Frequently Asked Question (FAQ[1]): it is
            utter nonsense to try to simulate that behavior with window.open()
            by programmaticall y trying to force the focus on the popup window,
            because that is very likely to make the rest of the GUI unusable.


            PointedEars
            ___________
            [1] <URL:http://jibbering.com/faq/>

            Comment

            • korund@hotmail.com

              #7
              Re: formatting text in JavaScript popup boxes

              Thomas 'PointedEars' Lahn писал(а):

              korund@hotmail. com wrote:

              We can use special characters ('\n') to add line breaks in text in
              JavaScript popup Alert boxes.
              [color=blue]
              > True.[/color]

              there is also few additional special characters:

              \' single quote
              \" double quote
              [color=blue]
              > Those are not special characters in any way. They are escape sequences
              > required only when the escaped character already serves as a string literal
              > delimiter.
              >[/color]
              \& ampersand[color=blue]
              > Well, the same goes for \a, \c, \d and so on in string literals, because it
              > is not a valid escape sequence. The ampersand does not need to be escaped.[/color]

              \\ backslash
              [color=blue]
              > Again, that is not a special character, but an escape sequence for the
              > backslash character, which serves as escape sequence prefix itself
              > (hence the requirement to escape it if the literal character is needed).[/color]

              \n new line
              \r carriage return
              \t tab
              \b backspace
              \f form feed
              [color=blue]
              > That is true, and the characters displayed by those escape
              > sequences are the only special characters you mentioned.[/color]
              [color=blue]
              > ECMAScript Edition 3 also defines the escape sequence[/color]

              \v (equivalent to \u000B)
              [color=blue]
              > for the <VT> (Vertical Tab) character (U+000B). See ECMAScript Edition 3
              > Final, subsection 7.8.4.[/color]

              Is there also additional characters for more reach formatting? (bold
              text, etc)?
              [color=blue]
              > No.[/color]

              Need we put "\n" inside quotations?
              [color=blue]
              > I do not know if you have to; I have, as I prefer to have running code.
              > \n is an escape sequence valid within (string and RegExp) literals only.[/color]

              Is there some Javascript popup Alert box text formatter, to format text
              from GUI, more handy way?
              [color=blue]
              > No. You will have to create your own popup window. There are some
              > proprietary approaches, such as showModalDialog () in the IE DOM, that
              > support you in creating modal windows as you know them from window.alert():[/color]

              Image
              Gain technical skills through documentation and training, earn certifications and connect with the community

              [color=blue]
              > Gecko-based UAs have window.open(... , ..., "modal") and window.openDial og():[/color]

              Image
              The Window interface represents a window containing a DOM document; the document property points to the DOM document loaded in that window.

              [color=blue]
              > But none of these is interoperable.[/color]
              [color=blue]
              > And to save you another Frequently Asked Question (FAQ[1]): it is
              > utter nonsense to try to simulate that behavior with window.open()
              > by programmaticall y trying to force the focus on the popup window,
              > because that is very likely to make the rest of the GUI unusable.[/color]
              [color=blue]
              > PointedEars[/color]
              ___________[color=blue]
              > [1] <URL:http://jibbering.com/faq/>[/color]
              ------------------------------------------------------
              Addind a quotations "\n" cause adding it also to text and new line
              both, so it not required, probably.

              Korund

              Comment

              • Richard Cornford

                #8
                Re: formatting text in JavaScript popup boxes

                korund@hotmail. com wrote:[color=blue]
                > We can use special characters ('\n') to add line breaks
                > in text in JavaScript popup Alert boxes.[/color]
                <snip>[color=blue]
                > Is there also additional characters for more reach
                > formatting? (bold text, etc)? Need we put "\n" inside
                > quotations?
                > Is there some Javascript popup Alert box text formatter,
                > to format text from GUI, more handy way?[/color]

                There is quite a wide school of thought that regards the alert, prompt
                and confirm facilities of web browsers as utterly inappropriate and
                inadequate for use in a real world GUI; that they are at best
                learning/debugging tools and should never be exposed to the end user.
                This is not least because they have inconsistent and extremely limited
                (and largely undesirable) display characteristics .

                Richard.


                Comment

                • Richard Cornford

                  #9
                  Re: formatting text in JavaScript popup boxes

                  Thomas 'PointedEars' Lahn wrote:[color=blue]
                  > korund@hotmail. com wrote:[/color]
                  <snip>[color=blue][color=green]
                  >> \& ampersand[/color]
                  >
                  > Well, the same goes for \a, \c, \d and so on in string literals,[/color]

                  This is true.
                  [color=blue]
                  > because it is not a valid escape sequence.[/color]

                  This is questionable. Because \a is a valid EscapeSequence (ECMA 262,
                  3rd Ed. Section 7.8.4). The backslash followed by EscapeSequence, where
                  EscapeSequence is one of 0, CharacterEscape Sequence, HexEscapeSequen ce
                  or UnicodeEscapeSe quence is a SingleStringCha racter. And
                  CharacterEscape Sequence is either SingleEscapeCha racter or
                  NonEscapeCharac ter, where NonEscapeCharac ter is any SourceCharacter that
                  is not an EscapeCharacter or LineTerminator.

                  So any character (with the explicit exception of LineTerminators )
                  preceded by a backslash may be a valid EscapeSequence but if the
                  character is not one of the set that is SingleEscapeCha racter the result
                  of the EscapeSequence is just the character itself.

                  \a is the equivalent of a, pointless but allowed by the syntax.
                  [color=blue]
                  > The ampersand does not
                  > need to be escaped.[/color]

                  No it does not need to be escaped.

                  <snip>[color=blue]
                  > ECMAScript Edition 3 also defines the escape sequence
                  >
                  > \v (equivalent to \u000B)
                  >
                  > for the <VT> (Vertical Tab) character (U+000B). See
                  > ECMAScript Edition 3 Final, subsection 7.8.4.[/color]
                  <snip>

                  True, but as I recall IE gets this wrong and treats \v as a literal v.
                  Still, how often have you used vertical tabs to date? For me it is
                  never, and that is one of the reasons that I use vertical tabs
                  ('\u000B') as separators in strings that need to be split up using a
                  character separator, as alternatives such as |, ~, ^, etc. have proved
                  insufficiently unusual in the past.

                  Richard.


                  Comment

                  • korund@hotmail.com

                    #10
                    Re: formatting text in JavaScript popup boxes

                    > Addind a quotations "\n" cause adding it also to text and new line[color=blue]
                    > both, so it not required, probably.[/color]
                    ----------------------


                    Hence, correct syntax is without double quotations, i.e. \n , \r , etc

                    Korund

                    Comment

                    • Dr John Stockton

                      #11
                      Re: formatting text in JavaScript popup boxes

                      JRS: In article <1144407080.594 109.282140@t31g 2000cwb.googleg roups.com>
                      , dated Fri, 7 Apr 2006 03:51:20 remote, seen in
                      news:comp.lang. javascript, korund@hotmail. com posted :[color=blue]
                      >
                      >Is there also additional characters for more reach formatting? (bold
                      >text, etc)?[/color]

                      AFAIK no, apart maybe from \v .

                      However, AFAICS no-one has yet mentioned the use of \uHHHH where H is a
                      hexadecimal digit - try alert("\u20ac") - though it may be that not many
                      of them work reliably (user font dependence).


                      --
                      © John Stockton, Surrey, UK. [email protected]. 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.htm> jscr maths, dates, sources.
                      <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

                      Comment

                      Working...