Window.location Javascript JS重定向

时间:2019-03-08 02:41:31

标签: javascript redirect window.location

我有这个:

                setTimeout(function () {
              $.dialog({
                title: 'Existing user',
                content: "This account is already registered on our system. If you are the real owner, contact us!",
                icon: 'fas fa-user',
                theme: 'modern',
                animation: 'scale',
                type: 'red',
                draggable: false,
                closeIcon: function(){
                              window.location="/dashboard";
                          },
              });
            }, 200);

一旦用户单击“ closeIcon”,我需要在5秒后重定向用户。问题是,如果我使用此对话框,则永远不会显示该对话框:

                    closeIcon: setTimeout(function () {
                              window.location="/dashboard";
                          }, 5000);
              });

我该怎么办?

谢谢!

编辑:

我也尝试过这种方法,但是不起作用:

                function () {
              $.dialog({
                title: 'Existing user',
                content: "This account is already registered on our system. If you are the real owner, contact us!",
                icon: 'fas fa-user',
                theme: 'modern',
                animation: 'scale',
                type: 'red',
                draggable: false,
                closeIcon: setTimeout(function () {
                              window.location="/dashboard";
                          }, 5000);
              });
            }

3 个答案:

答案 0 :(得分:0)

closeIcon: function () {
  setTimeout(function () {
      window.location="/dashboard";
  }, 5000);
}
改为执行此操作。

答案 1 :(得分:0)

问题是setTimeout returns a positive integer,但是closeIcon需要功能。使用arrow function (ES6)封装计时器可以解决此问题。您还可以使用常规函数。

setTimeout(function () {
    $.dialog({
        title: 'Existing user',
        content: "This account is already registered on our system. If you are the real owner, contact us!",
        icon: 'fas fa-user',
        theme: 'modern',
        animation: 'scale',
        type: 'red',
        draggable: false,
        closeIcon: ()=> {
            setTimeout(()=>window.location = "/dashboard",2000);
        },
    });
}, 200);

答案 2 :(得分:0)

是否有一种方法可以在多语言站点上实现此目的,以便使“ / dashboard”重定向到站点上的每种特定语言?