繁体   English   中英

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

[英]Sweet Alert 2 and javascript:How do i make a Sweet alert button that sends me to a certain webpage when clicked

到目前为止我的代码:

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.value) { 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。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM