我有这个代码从客户端网站获取值:
var server = ws.createServer(function(conn){
console.log("New Connection");
//on text function
conn.on("text", function(str){
/* here i was to take that value in the str and pass it to html file which is path "agent/index.html"*/
});
}).listen(process.env.PORT, process.env.IP);
我想在agent / index.html文件中使用 str 值并对其执行某些操作。
此 str 值来自使用 websockets 的远程用户网站现在我希望此值传递给代理,此代理会立即回复它,它是实时聊天应用
请检查评论。
答案 0 :(得分:1)
你有很多选择。 Cookie,localstorage,URL参数,POST数据并存储(可能不建议)。
如果您只想要该页面的数据,我只会使用URL参数。在您的函数内部,将用户重定向到agent / index.html?text = str和index.html,检索URL参数,并使用它执行您喜欢的操作。