首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >甜蜜警报2和javascript:如何制作一个甜蜜警报按钮,在点击时将我发送到某个网页

甜蜜警报2和javascript:如何制作一个甜蜜警报按钮,在点击时将我发送到某个网页
EN

Stack Overflow用户
提问于 2017-04-26 01:05:20
回答 2查看 5.7K关注 0票数 2

到目前为止我的代码如下:

代码语言:javascript
复制
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:

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-04-26 22:07:03

下面是如何使用SweetAlert2实现的

代码语言:javascript
复制
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.value) {
     location.assign("https://stackoverflow.com/")
   }
 });
代码语言:javascript
复制
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

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

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

票数 6
EN

Stack Overflow用户

发布于 2019-02-24 07:47:09

这是我用来在点击时重定向的东西(OK)

代码语言:javascript
复制
<script>
sweetAlert({title: 'Error',text: 'Invalid OTP',type: 'error',onClose: function(){
        window.location.href = 'https://google.com';
}});
</script>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43616916

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档