Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format the text in JavaScript alert box

How can I format the text in a JavaScript alert box? I need a word in the text to be underlined.

like image 542
praveen Avatar asked Jul 04 '13 12:07

praveen


People also ask

Can you style alert box JavaScript?

The standard alert box in JavaScript does not provide the option to apply CSS. To style your alert box, you need to create a custom one first. The custom alert box will be created using jQuery and styles will be applied to CSS.

How do I display text in alert box?

The Window alert() method is used to display an alert box. It displays a specified message along with an OK button and is generally used to make sure that the information comes through the user. It returns a string which represents the text to display in the alert box.

How do I change the title of an alert () box in JavaScript?

It's not possible to edit a JavaScript alert box title due to security issues. Still, to edit an alert box to work it all web browsers, use custom JavaScript Modal Dialogs or jQuery plugins.


2 Answers

You can use only:

\b = Backspace  \f = Form feed  \n = New line  \r = Carriage return  \t = tab \000 = octal character  \x00 = hexadecimal character  \u0000 = hexadecimal unicode character 

So, you can insert different ASCII characters, but not format them (like italic or bold).

EDIT I also have to mention, that in fact alert acts like toString conversion, so including tags and/or styles is not possible.

like image 149
vladkras Avatar answered Sep 21 '22 14:09

vladkras


Underline a string using unicode character '\u0332', called a COMBINING LOW LINE

function underline(s) {     var arr = s.split('');     s = arr.join('\u0332');     if (s) s = s + '\u0332';     return s; }  var str = underline('hello world'); // "h̲e̲l̲l̲o̲ ̲w̲o̲r̲l̲d̲"  alert(str); 

This method is not guaranteed to produce a smooth underline.

Example of confirm() on Firefox 59:

firefox confirm u0332

like image 29
Paul S. Avatar answered Sep 21 '22 14:09

Paul S.