javascript - 甜蜜警报 2 和 javascript :How do i make a Sweet alert button that sends me to a certain webpage when clicked

标签 javascript jquery html sweetalert sweetalert2

到目前为止我的代码:

swal({ 
    title: 'Successfully Registered!', 
    text: "Do you want to go to the Log In page?", 
    type: 'success', 
    showCancelButton: true, 
    confirmButtonColor: '#3085d6', 
    cancelButtonColor: '#d33', 
    confirmButtonText: 'Yes, send me there!' 
    }, 
    function(){ 
       window.location.href= "http://example.com"; 
    }
); 

出于某种原因,window.location.href 无法正常工作,我尝试仅使用 location.href 和 if(isConfirm) 等。
我该怎么办?
JSFiddle: https://jsfiddle.net/2dz868kd/

最佳答案

以下是使用 SweetAlert2 实现的方法:

Swal.fire({
    title: 'Successfully Registered!',
    text: 'Do you want to go to the Log In page?',
    icon: 'success',
    showCancelButton: true,
    confirmButtonColor: '#3085d6',
    cancelButtonColor: '#d33',
    confirmButtonText: 'Yes, send me there!'
 }).then(function(result) {
   if (result.isConfirmed) {
     location.assign("https://stackoverflow.com/")
   }
 });
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

SweetAlert2 文档:https://sweetalert2.github.io/

请注意,SweetAlert2 和 SweetAlert 是两个不同的项目。 SweetAlert2 使用 ES6 Promises。

关于javascript - 甜蜜警报 2 和 javascript :How do i make a Sweet alert button that sends me to a certain webpage when clicked,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43616916/

相关文章:

javascript - 视差效果 - 强制文本 block 表现得像背景附件 : fixed

javascript - 带有 ES6 箭头函数的 jQuery .each() 函数

javascript - jQuery 和 Ajax 加载时的奇怪变量值

javascript - 从文档中的任何位置访问当前鼠标悬停的元素

javascript - 根据 id 比较两个数组并根据值返回一个新数组

javascript - 我可以在 Angular ng-style 指令中使用来自 API 调用的数据吗?

JavaScript 匹配数组

html - 如何在 TBody 中将 TH Header 与 TD 对齐

javascript - 禁用缓存 YouTube 视频

jQuery:追加一次并停止(在旧版本中有效)