提问者:小点点

如何使用nodejs在几秒钟后自动切换下一页


//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)每当我运行服务器时,它应该转到主页,几秒钟后自动转到下一页


共2个答案

匿名用户

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

window.location = "/thankyou";

匿名用户

你可以这样做:

// 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>