---
# System prepended metadata

title: Sweetalert2

---

# Sweetalert2

## 基本使用，以及用heightAuto防止畫面跑掉
```
//基本
swal("alert")   

//設定options
swal({       
  type: "error",
  title: "Oops...",
  text: "連線逾時，重新再試!",
  heightAuto: false
});

//確認後執行
swal({
    title: "重置成功",
    text: "請重新登入!",
    type: "success",
    heightAuto: false
}).then(result => {
    if (result.value) {
      location.href = "/login.html";
    }
});

//刪除選項
swal({
  title: 'Are you sure?',
  text: "You won't be able to revert this!",
  type: 'warning',
  showCancelButton: true,
  confirmButtonColor: '#3085d6',
  cancelButtonColor: '#d33',
  confirmButtonText: 'Yes, delete it!'
}).then((result) => {
  if (result.value) {
    swal(
      'Deleted!',
      'Your file has been deleted.',
      'success'
    )
  }
})
```

