Sweet Alert 2 - Link in "confirmButtonText" 按钮

Sweet Alert 2 - Link in "confirmButtonText" button

我想知道如何在生成 Sweet Alert 2confirmButtonText 的按钮中放置 link。

目标是当您按下该按钮时重定向到一个页面,该页面从数据库中删除一条记录,直到现在我在一个简单的按钮中使用一个简单的 link (<a>) , 但我想添加这个小确认。

代码如下:

按键如下:

你可以在 sweet alert2 中使用 promising

Swal.fire({
 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.fire(
   'Deleted!',
   'Your file has been deleted.',
   'success'
 )
}
})

更多,检查:https://sweetalert2.github.io/

这行得通!

confirmButtonText: '<a href="url">LINK</a>'

我所做的是将一个函数附加到使用 window.href 跟随 link 的确认按钮:

Swal.fire({
   title: '<strong>Are you sure?</strong>',
   icon: 'warning',
   html:`You really can't go back after this, We can't retrieve it either!`,
   showCloseButton: true,
   showCancelButton: true,
   focusConfirm: false,
   reverseButtons: true,
   focusCancel: true,
   cancelButtonText:`Blue pill`,
   confirmButtonText:`Red pill`
 }).then((result) => {
   if (result.value) {
     window.location.href = `/real_world`
   }
 }); 

我想我来不及回复查询了,但这可能会对搜索类似内容的其他人有所帮助。

Swal.fire({
        title: '<strong>Check Redirect!!</strong>',
        icon: 'success',
        showConfirmButton: false,
        allowOutsideClick: false,
        footer:`<a class="btn btn-primary" href="https://www.google.com">OK</a>`
    });

使用window.open

Swal.fire({
  title: 'Are you sure?',
  text: "You won't be able to revert this!",
  icon: 'warning',
  showCancelButton: true,
  confirmButtonColor: '#3085d6',
  cancelButtonColor: '#d33',
  confirmButtonText: 'Yes, delete it!',
  cancelButtonText: 'No'
}).then((result) => {
  if (result.isConfirmed) {
     window.open("https://www.google.com.br");
  }
})