formatting text in JavaScript popup boxes

K

korund

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?
 
O

[on]

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?

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)
 
K

korund

My question was about the JavaScript popup Alert boxes.

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

korund

Right and I answerd you.
Btw: please quote the message you're responding to.
--------------------------------------------

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?
 
T

Thomas 'PointedEars' Lahn

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

there is also few additional special characters:

\' single quote
\" double quote

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.
\& ampersand

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.
\\ backslash

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).
\n new line
\r carriage return
\t tab
\b backspace
\f form feed

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)

Is there also additional characters for more reach formatting? (bold
text, etc)?
No.

Need we put "\n" inside quotations?

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.
Is there some Javascript popup Alert box text formatter, to format text
from GUI, more handy way?

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.openDialog():

<URL:http://developer.mozilla.org/en/docs/DOM:window#Methods>

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 programmatically 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/>
 
K

korund

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

(e-mail address removed) wrote:

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
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.
\& ampersand
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.

\\ backslash
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).

\n new line
\r carriage return
\t tab
\b backspace
\f form feed
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.

Is there also additional characters for more reach formatting? (bold
text, etc)?

Need we put "\n" inside quotations?
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.

Is there some Javascript popup Alert box text formatter, to format text
from GUI, more handy way?
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():
http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/showmodaldialog.asp

Gecko-based UAs have window.open(..., ..., "modal") and window.openDialog():
http://developer.mozilla.org/en/docs/DOM:window#Methods

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 programmatically 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/>
 
R

Richard Cornford

Thomas said:
(e-mail address removed) wrote:

Well, the same goes for \a, \c, \d and so on in string literals,

This is true.
because it is not a valid escape sequence.

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, CharacterEscapeSequence, HexEscapeSequence
or UnicodeEscapeSequence is a SingleStringCharacter. And
CharacterEscapeSequence is either SingleEscapeCharacter or
NonEscapeCharacter, where NonEscapeCharacter 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 SingleEscapeCharacter the result
of the EscapeSequence is just the character itself.

\a is the equivalent of a, pointless but allowed by the syntax.
The ampersand does not
need to be escaped.

No it does not need to be escaped.

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.
<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.
 
R

Richard Cornford

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?

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.
 
K

korund

Addind a quotations "\n" cause adding it also to text and new line
both, so it not required, probably.
----------------------


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

Korund
 
D

Dr John Stockton

JRS: In article <[email protected]>
, dated Fri, 7 Apr 2006 03:51:20 remote, seen in
Is there also additional characters for more reach formatting? (bold
text, etc)?

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).
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top