Can I put formatted HTML code as Javascript alert() input parameter? - Stack Overflow

I have this simpe Javascript script that show a popup box when a link is clicked:<script>function

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
Add a ment  | 

2 Answers 2

Reset to default 3

No, 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");

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745449369a4628196.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信