New line in JavaScript alert box

Viewed 545773

How do you put in a new line into a JavaScript alert box?

20 Answers

You can use \n for new line

alert("Welcome\nto Jumanji");

alert("Welcome\nto Jumanji");

In JAVA app, if message is read from "properties" file.

Due to double compilation java-html,

you'll need double escape.

jsp.msg.1=First Line \\nSecond Line

will result in

First Line
Second Line
Related