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.com!" + '\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.
Go to Settings > System > Notifications & actions and make sure the Notifications option is toggled on. Afterward, scroll to the Get notifications from these senders section and make sure Google Chrome is toggled on.
The reason alert() does not work is because previously you have checked "prevent this page from creating additional dialoug" checkbox. lets take a look at this code. There will be two alert boxes if you run the code.
Seems to have been an issue for awhile sadly :(
http://productforums.google.com/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?
As 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.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="btnShowAlert">Show Alert</button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With