【问题标题】:Sweet Alert Redirection to URL using ASP.NET Core (default Ok button)使用 ASP.NET Core 将 Sweet Alert 重定向到 URL(默认确定按钮)
【发布时间】:2021-10-23 23:05:10
【问题描述】:

下面的Javascript 函数仍然无法指向相关的URL,尽管我看不到任何异常。因此,导致这篇文章的困惑。

if(msg) {
if (msg.provider == "sweetAlert") {
    swal.fire({
        title: msg.title,
        text: msg.text,
        icon: msg.icon,
        timer: 5000,
        confirmButtonColor: "black",
        BorderColor: "white"
    }, function(){
        var url ='@Url.Action("Action","Controller")';
        window.location.href = url;
    });
} 

因此,我们将非常感谢任何相关的反馈。

提前致谢。 最好的

【问题讨论】:

    标签: javascript asp.net-mvc asp.net-core sweetalert sweetalert2


    【解决方案1】:
    Swal.fire({
        title: 'Some title',
        showCancelButton: true,
        confirmButtonText: 'Go to Google',
    }).then((result) => {
        if (result.value) {
            var url = 'https://www.google.co.uk/';
            window.location = url;
        }
    });
    

    使用then 函数处理回调。如果result.valuetrue 表示用户点击了确定按钮。

    $(document).ready(function () {
        Swal.fire({
            title: 'Some title',
            showCancelButton: true,
            confirmButtonText: 'Go to Google',
        }).then((result) => {
            if (result.value) {
                alert('user click on Okay button');
                var url = 'https://www.google.co.uk/';
                window.location = url;
            }
            else {
                alert('user click on Cancel button');
            }
        });
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>

    【讨论】:

    • 感谢您的反馈,特别是指出缺少的 then 函数来处理回调。非常感谢 - 谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-07
    • 1970-01-01
    相关资源
    最近更新 更多