Window.location Javascript JS Redirect

问题描述 投票:-1回答:3

我有这个:

                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);
              });
            }
javascript redirect window.location
3个回答
0
投票

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

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);

0
投票

有没有办法在多语言网站上实现这一点,以便“/ dashboard”重定向到网站上的每种特定语言?

© www.soinside.com 2019 - 2024. All rights reserved.