Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create and apply CSS to javascript Alert

Please tell me, how to apply CSS on javascript Alert. Thanks

like image 634
Dr. Rajesh Rolen Avatar asked Apr 02 '10 04:04

Dr. Rajesh Rolen


People also ask

Can you style a JavaScript alert?

The standard alert box in JavaScript does not provide the option to apply CSS. To style your alert box, you need to create a custom one first. The custom alert box will be created using jQuery and styles will be applied to CSS.

Can you add CSS to JavaScript?

The CSS file is used to describe how HTML elements will be displayed. There are various ways to add CSS file in the HTML document. JavaScript can also be used to load a CSS file in the HTML document.

How do I create an alert in JavaScript?

One useful function that's native to JavaScript is the alert() function. This function will display text in a dialog box that pops up on the screen. Before this function can work, we must first call the showAlert() function. JavaScript functions are called in response to events.

How do I use alert box in CSS?

We will assign a class to the alert box, after that, we design that specific class in CSS. In this example, the class is a container. To design the button we will use the button tag in the CSS to design it. And the appeared messages also can be decorated like we attach a class and can design that too.


3 Answers

You cannot. alert() simply shows a native message box, so it'll look however the OS makes it look.

In general, you shouldn't be using alert boxes because they are annoying and they block the entire browser.* You could always create a fake alert box with JavaScript that achieves the same effect. You could then style it however you want with normal CSS. If you use jQuery, there's SimpleModal (demos).

* Modern browsers tend to only block the window that spawned the alert, but they're still annoying and you still shouldn't use them. :)

like image 66
Sasha Chedygov Avatar answered Oct 12 '22 23:10

Sasha Chedygov


It is not possible, or else people will use it to phish.

like image 22
Ming-Tang Avatar answered Oct 13 '22 01:10

Ming-Tang


you might want to check jConfirm (jQuery plugin)

http://abeautifulsite.net/2008/12/jquery-alert-dialogs/

like image 35
slier Avatar answered Oct 13 '22 01:10

slier