Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

javascript

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.

like image 831
designersvsoft Avatar asked Jul 11 '12 05:07

designersvsoft


People also ask

Why alert is not working in Chrome?

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.

Why is my alert function not working?

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.


2 Answers

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?

like image 74
Matthew 'mandatory' Bryant Avatar answered Sep 18 '22 19:09

Matthew 'mandatory' Bryant


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>
like image 20
Trevor Avatar answered Sep 17 '22 19:09

Trevor