【问题标题】:Sweet Alert 2 and javascript:How do i make a Sweet alert button that sends me to a certain webpage when clickedSweet Alert 2 和 javascript:我如何制作一个 Sweet Alert 按钮,点击后将我发送到某个网页
【发布时间】:2017-04-25 17:05:20
【问题描述】:

到目前为止我的代码:

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/

【问题讨论】:

  • 您应该将代码上传到jsfiddle,以便用户可以看到演示并在那里进行更改。
  • 我做到了,谢谢你的建议。

标签: javascript jquery html sweetalert sweetalert2


【解决方案1】:

以下是使用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。

【讨论】:

  • 哥们,你不知道我有多爱你!我花了太多时间试图弄清楚。
【解决方案2】:

这是我用来重定向点击(确定)

<script>
sweetAlert({title: 'Error',text: 'Invalid OTP',type: 'error',onClose: function(){
        window.location.href = 'https://google.com';
}});
</script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-18
    • 1970-01-01
    • 2017-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-10
    相关资源
    最近更新 更多