Tab '\ t' in warning box not working with Chrome

I want to display three lines of text in a Javascript warning window with the text aligned to the center.

I use the following code for this

alert( '\t\t\t\t'+"Congratulations!" + '\n\t' + "You are now subscribed with test.com!" + '\n' + "Keep on eye out on your inbox for future updates from us!" ); 

It works great with Firefox. But in chrome, the tab character ( \t ) does not work. Texts are left-aligned in all lines. Please help.

+6
source share
2 answers

It seems that this was a problem for a while sadly :(

http://productforums.google.com/forum/#!topic/chrome/bfmvqAvtSd4

Found that this makes impossible.

Perhaps use something to simulate a warning window?

+3
source

You can use a few spaces as a workaround. For instance...

 <script> alert('Food:\n Apples\n Bread\n Carrots'); </script> 

Working example:

 $(function(){ $('#btnShowAlert').on('click', function(){ alert('Food:\n Apples\n Bread\n Carrots'); }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button id="btnShowAlert">Show Alert</button> 
+2
source

Source: https://habr.com/ru/post/920182/


All Articles