javascript - 我可以在一段时间间隔(例如 10 秒)后将 innerHTML 文本重定向回我的主页吗?

标签 javascript html

当我注册一个新帐户并且一切顺利时,这部分代码将运行并更改表单以显示消息“检查您的电子邮件[...]”。我试图让消息仅显示几秒钟,然后重定向回主页。

_("signupbutton").style.display = "none";
        status.innerHTML = 'please wait ...';
        var ajax = ajaxObj("POST", "signup.php");
        ajax.onreadystatechange = function() {
            if(ajaxReturn(ajax) == true) {
                if(ajax.responseText != "signup_success"){
                    status.innerHTML = ajax.responseText;
                _("signupbutton").style.display = "block";
                }else {
                    window.scrollTo(0,0);
                    _("wrap").innerHTML = "<div >Check your email inbox to complete the sign up process by activating your account.</div>";

最佳答案

正如评论中提到的,您只需要使用 setTimeoutlocation

_("signupbutton").style.display = "none";
        status.innerHTML = 'please wait ...';
        var ajax = ajaxObj("POST", "signup.php");
        ajax.onreadystatechange = function() {
            if(ajaxReturn(ajax) == true) {
                if(ajax.responseText != "signup_success"){
                    status.innerHTML = ajax.responseText;
                _("signupbutton").style.display = "block";
                }else {
                    window.scrollTo(0,0);
                    _("wrap").innerHTML = "<div >Check your email inbox to complete the sign up process by activating your account.</div>";
                    setTimeout(function() {
                      window.location = 'homepage.html'; // or whatever the URL is
                    }, 10000);

关于javascript - 我可以在一段时间间隔(例如 10 秒)后将 innerHTML 文本重定向回我的主页吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26569582/

相关文章:

php - onClick 重新加载 div 中的图像

javascript - .data() 没有按预期工作

javascript - jQuery 将本地文件移动到另一个目录

html - 如何创建带有列和行部分标题的 html 表格

javascript - jQuery fadeIn(), fadeOut() 导致性能急剧下降

javascript - Angular 使用 ng-model 选择一个选项

javascript - 使用 JavaScript/html;如何在打印区域之外打印 Canvas ?

html - div 显示在另一个 div 下

javascript - 如何防止数据表中特定列的行点击功能?

javascript - 如何在父类(super class)静态函数中引用子类的静态参数?