I have this simpe Javascript script that show a popup box when a link is clicked:
<script>
function myExample() {
alert("BaZing! It works!");
}
</script>
I want to know if it is possible to format the text inside the alert() function.
In particular I want to know if (and how) is it possible to put some formatted HTML text as alert() input parameter.
Some one can help me?
I have this simpe Javascript script that show a popup box when a link is clicked:
<script>
function myExample() {
alert("BaZing! It works!");
}
</script>
I want to know if it is possible to format the text inside the alert() function.
In particular I want to know if (and how) is it possible to put some formatted HTML text as alert() input parameter.
Some one can help me?
Share Improve this question edited Oct 5, 2013 at 16:37 furins 5,0481 gold badge42 silver badges58 bronze badges asked Oct 5, 2013 at 16:33 AndreaNobiliAndreaNobili 43.1k122 gold badges364 silver badges682 bronze badges 2- As long as it's a string, you can put anything you'd like in there? HTML and styles doesn't work on OS/browser specific windows, obviously! – adeneo Commented Oct 5, 2013 at 16:34
- You can't, use a custom modal. – alex Commented Oct 5, 2013 at 16:34
2 Answers
Reset to default 3No, alert()
accepts one string argument and will display it as is.
If you need to display a formatted text in a modal, use a library (e.g. Alertify.js).
alert() can't format a HTML format string, but if you just want separate a string to several lines, you can put '\n' in your string,like
alert("first line \n second line \n third line");