【问题标题】:how to switch next pages automatically after few seconds using nodejs如何使用nodejs在几秒钟后自动切换下一页
【发布时间】:2020-07-27 12:33:44
【问题描述】:
//written in javascript
<script>
  setTimeout(function () {
     // after 2 seconds
     window.location = "/next-page";
  }, 2000)
</script>
//nodejs
app.get('/thankyou',function(req,res){
    res.render('thankyou' {message : 'Thank you for your submission'});
});

1)如何使用 nodejs 在几秒钟后自动切换下一页 2)每当我运行服务器时,它应该在几秒钟后自动转到主页

【问题讨论】:

    标签: javascript html node.js settimeout


    【解决方案1】:

    您可以标记 window.location = '/thankyou' 或将 nodejs 端的路由器更改为 '/next-page'

    window.location = "/thankyou";
    

    【讨论】:

      【解决方案2】:

      你可以这样做:

      // node.js:
      app.get('/thankyou',function(req,res){
          res.sendFile(__dirname+"/redirect.html");
      });
      
      // redirect.html
      <!DOCTYPE html>
      <html>
          <head>
              <title>Redirect</title>
          </head>
          <body>
              <script>
                  setTimeout(function(){
                      window.location = "/the-page";
                  },2000);
              </script>
          </body>
      </html>
      

      【讨论】:

      • 打印这个“path/to/redirect.html”。不渲染到下一页
      • 对不起,应该是sendFile
      • 请查看最新版本。
      • app.use('/the-page',()=> { res.send("

        welcome to second page

        ") }) 转到第二页但没有显示内容
      • 什么都不显示?
      猜你喜欢
      • 1970-01-01
      • 2016-06-03
      • 1970-01-01
      • 1970-01-01
      • 2015-06-03
      • 1970-01-01
      • 1970-01-01
      • 2016-02-20
      • 1970-01-01
      相关资源
      最近更新 更多