简体   繁体   English

如何在 res.send 中通过 javascript function

[英]how to pass javascript function inside res.send

//defined in xyz.js
function getRedirectPage(pageName) {
  setTimeout(function(){
              window.location = "/"+pageName;
            },3000);
}
  
//server code
app.get('',function(req,res){
    res.send("<script>getRedirectPage('page1')</script>")
    
});

  1. how to define function in res.send如何在 res.send 中定义 function
  2. whenever i run the server it should call the getRedirectPage('page1') it will go to js code.每当我运行服务器时,它应该调用 getRedirectPage('page1') 它将 go 转换为 js 代码。 from there it will run after few seconds从那里它将在几秒钟后运行

you should add href method and change it to redirect, see the code below您应该添加 href 方法并将其更改为重定向,请参见下面的代码

 function getRedirectPage(pageName) { setTimeout(function () { window.location.href = "/" + pageName; }, 3000); } app.get('',function(req,res){ res.redirect("<script>getRedirectPage('page1')</script>") });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM