DEV Community

Dhiman_aman
Dhiman_aman

Posted on

How to add window alert on screen or Sweet Alert ?

Use Library

  • Sweet Alert
https://sweetalert.js.org/guides/
Enter fullscreen mode Exit fullscreen mode
  • Add the CDN link <script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.0/sweetalert.min.js"></script>

Complete Code

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Sweer Alert</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.0/sweetalert.min.js"></script>
  </head>
  <body>
    <center>
      <h1>Sweet Alert</h1>
      <p>
        Link :
        <a href="https://sweetalert.js.org/guides/" target="_blank">
          Sweet Alert Website</a
        >
      </p>
      <button onclick="alertFunction()">Alert Function</button>
    </center>
    <script>
      alertFunction = () => {
        swal("Sweet Alert", "on Click function ", "success", {
          button: "OK",
        });
      };
    </script>
  </body>
</html>

Enter fullscreen mode Exit fullscreen mode

Image description

Top comments (0)