I want to display three lines of text in a Javascript alert box with center alignment of text.
I'm using the following code for that,
alert(
'\t\t\t\t'+"Congratulations!" + '\n\t' +
"You are now subscribed with test!" + '\n' +
"Keep on eye out on your inbox for future updates from us!"
);
It's working fine with Firefox. But in chrome, the tab (\t
) character is not working. Texts are left aligned in all lines. Please help.
I want to display three lines of text in a Javascript alert box with center alignment of text.
I'm using the following code for that,
alert(
'\t\t\t\t'+"Congratulations!" + '\n\t' +
"You are now subscribed with test.!" + '\n' +
"Keep on eye out on your inbox for future updates from us!"
);
It's working fine with Firefox. But in chrome, the tab (\t
) character is not working. Texts are left aligned in all lines. Please help.
-
4
You really shouldn't rely on text positioning in
alert()
boxes. You also really shouldn't use an alert box for telling someone they're subscribed. Just put a message on the page. – Amber Commented Jul 11, 2012 at 5:05 - 1 alertbox is waaaaaay aged man ! try other cool things like colorbox jacklmoore./colorbox and also alertbox is a part of the browser ,which has minimal style functionalities – coolguy Commented Jul 11, 2012 at 5:07
3 Answers
Reset to default 5As a workaround, you can use several spaces instead. E.g...
<script>
alert('Food:\n Apples\n Bread\n Carrots');
</script>
A working example:
$(function(){
$('#btnShowAlert').on('click', function(){
alert('Food:\n Apples\n Bread\n Carrots');
});
});
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="btnShowAlert">Show Alert</button>
Seems to have been an issue for awhile sadly :(
http://productforums.google./forum/#!topic/chrome/bfmvqAvtSd4
Found that and it makes it out to look like it's not possible.
Perhaps use something that'd mimic an alert box in appearance?
This works for me:
alert("Name: \u00A0Jose \u00A0Garcia");
\u00A0
is the non-breaking space character. I know it's not a tab per se, but \t
gives me a weird line before the text like this:
-Text
, so I ended up using \u00A0
instead. Hope this helps!