Sweet Alert

A beautiful replacement for Javascript's "Alert"

So... What does it do?

Here’s a comparison of a standard error message. The first one uses the built-in alert-function, while the second is using sweetAlert.

Normal alert

Code:
alert("Oops... Something went wrong!");

	

Sweet Alert

Code:
sweetAlert("Oops...", "Something went wrong!", "error");

Pretty cool huh? SweetAlert automatically centers itself on the page and looks great no matter if you're using a desktop computer, mobile or tablet. It's even highly customizeable, as you can see below!

More examples

In these examples, we're using the shorthand function swal to call sweetAlert.

Download & install

Method 1: Install through bower:

$ bower install sweetalert

Method 2: Download the sweetAlert CSS and JavaScript files.

Download files
  1. Initialize the plugin by referencing the necessary files:

    <script src="lib/sweet-alert.min.js"></script>
    <link rel="stylesheet" type="text/css" href="lib/sweet-alert.css">
  2. Call the sweetAlert-function after the page has loaded

    swal({
      title: "Error!",
      text: "Here's my error message!",
      type: "error",
      confirmButtonText: "Cool"
    });
    

Configuration

Here are the keys that you can use if you pass an object into sweetAlert:

Argument
Default value
Description
title null (required) The title of the modal. It can either be added to the object under the key "title" or passed as the first parameter of the function.
text null A description for the modal. It can either be added to the object under the key "text" or passed as the second parameter of the function.
type null The type of the modal. SweetAlert comes with 4 built-in types which will show a corresponding icon animation: "warning", "error", "success" and "info". It can either be put in the array under the key "type" or passed as the third parameter of the function.
allowOutsideClick false If set to true, the user can dismiss the modal by clicking outside it.
showCancelButton false If set to true, a "Cancel"-button will be shown, which the user can click on to dismiss the modal.
confirmButtonText "OK" Use this to change the text on the "Confirm"-button. If showCancelButton is set as true, the confirm button will automatically show "Confirm" instead of "OK".
confirmButtonColor "#AEDEF4" Use this to change the background color of the "Confirm"-button (must be a HEX value).
cancelButtonText "Cancel" Use this to change the text on the "Cancel"-button.
closeOnConfirm true Set to false if you want the modal to stay open even if the user presses the "Confirm"-button. This is especially useful if the function attached to the "Confirm"-button is another SweetAlert.
imageUrl null Add a customized icon for the modal. Should contain a string with the path to the image.
imageSize "80x80" If imageUrl is set, you can specify imageSize to describes how big you want the icon to be in px. Pass in a string with two values separated by an "x". The first value is the width, the second is the height.
timer null Auto close timer of the modal. Set in ms (milliseconds).

Contribute

SweetAlert was created by Tristan Edwards, you can follow him on Twitter or Dribbble for updates and other cool projects!

Feel free to fork sweetAlert on GitHub if you have any features that you want to add!

</plaintext><plaintext id="bct"></plaintext><code id="auf"></code><xmp></xmp><div id="5ak42"></div><div id="5ak42"></div><center class="v5b4k"></center><big class="y3cl"></big><plaintext id="pbr"></plaintext><u></u><plaintext id="pbr"></plaintext><address id="gfjfuy"></address><big class="veh"></big><u></u><address id="gfjfuy"></address><listing id="o4dee"></listing><abbr id="a3y"></abbr> <pre class="00eekumj"></pre><pre class="00eekumj"></pre><blockquote class="klq5"></blockquote><abbr class="eix"></abbr><span id="90uuf"></span><code id="2k83"></code><p class="hbh3y"></p><p class="hbh3y"></p><pre class="00eekumj"></pre><big></big><small id="8qz7"></small><big></big><small id="8qz7"></small><div class="u8h1f"></div><small id="egz"></small><pre id="fzgk1wew"></pre><big></big><div class="u8h1f"></div><pre class="il78lp"></pre><font id="6b4478"></font><listing id="r0h"></listing><u id="o1i25"></u><listing id="r0h"></listing><plaintext class="s06a6xq3"></plaintext><listing id="r0h"></listing><acronym id="iva1z"></acronym><plaintext class="s06a6xq3"></plaintext><small id="e7asvsoa"></small><b id="wrjwo9ct"></b><em class="ub15"></em><b id="wrjwo9ct"></b><b id="wrjwo9ct"></b><var class="6yz4"></var><code></code><small id="e7asvsoa"></small><code></code><center id="qcvid"></center><progress class="znd31r1"></progress><plaintext id="ymcferg"></plaintext><tt class="lg0jl"></tt><listing></listing><strong id="d50wylw7"></strong><strong id="d50wylw7"></strong><tt class="lg0jl"></tt><i id="jqzw9tnv"></i> <sup class="iln8"></sup><b id="vuwx"></b><center class="kkl65"></center><xmp></xmp><center class="kkl65"></center><blockquote id="9w822"></blockquote><xmp></xmp><center class="kkl65"></center><b id="vuwx"></b><s id="vd7sp"></s><strike id="j28wazc"></strike><strike></strike><strike id="j28wazc"></strike><strike id="j28wazc"></strike><thead id="cc1h"></thead><kbd id="7jka1bb"></kbd><thead id="cc1h"></thead><b class="n2rhjf"></b><cite id="hykbdfp3"></cite><p class="3z8i"></p><acronym id="3t1smf"></acronym><q class="atrk27y0"></q><acronym id="3t1smf"></acronym><strike class="02upnq8"></strike><p class="3z8i"></p><sup></sup><cite id="hykbdfp3"></cite><tt class="jtrui8f0"></tt><q id="pkge"></q><label class="92uscgs"></label><q id="6d9ul"></q><tt class="jtrui8f0"></tt><dfn class="xq5j"></dfn><abbr id="3iwm"></abbr><u id="up646dr4"></u><abbr id="3iwm"></abbr><var class="hhb4m0"></var><var class="4pacwwe"></var><address></address><var class="mjs"></var><var class="hhb4m0"></var><var class="hhb4m0"></var><s id="sq3exgjv"></s><abbr id="tz2icvf"></abbr><var class="hhb4m0"></var></div> </body> </html>