Skip to content Skip to sidebar Skip to footer

How To Stylize Text In An Alert Box?

Possible Duplicate: How to get Text BOLD in Alert or Confirm box? In the following example I need to add styles to the word alert, so it says: Hello! I am an alert box! Here

Solution 1:

Basically it's impossible. You don't have access to OS level from inside the browser.

All you can do is using a custom modal popup. You can find tons of ready to use modal popup plug ins here or here

window.alert accept an string as it's argument. You can't style an string

From MDN:

message is a string of text you want to display in the alert dialog, or, alternatively, an object that is converted into a string and displayed.

Solution 2:

The alert box is a browser window and part of the OS, not the DOM, so unfortunately you can't apply styles to it.

The easiest solution is to use one of many existing modal dialogs along with the required Javascript library of the dialog you choose.

The alternative is to mimic an alert box by overlaying a specialized <div class="yourAlertClass"> on your page, using Javascript or a custom library (like moo tools or jQuery) for the animations.

Solution 3:

You can't.

I think what you are thinking of is a modal popup. Have a look in JQuery UI, but there are plenty of other libraries you can use.

Solution 4:

Alert, confirm and promptcan not be styled. They vary from browser to browser.

To make a styled "alert box" ( dialog ) you should use an UI library - jQuery UI for example

Post a Comment for "How To Stylize Text In An Alert Box?"