比如客户端页面点击按钮的onclick事件,下载http://192.168.3.123:7077/users的页面,以.html格式保存 http://192.168.3.123:7077/users的对应路由代码:
var express = require(‘express’); var router = express.Router();
/* GET users listing. / router.get(’/’, function(req, res) { // res.send(‘respond with a resource123456’); var Cookies = {}; req.headers.cookie && req.headers.cookie.split(’;’).forEach(function( Cookie ) { var parts = Cookie.split(’=’); Cookies[ parts[ 0 ].trim() ] = ( parts[ 1 ] || ‘’ ).trim(); }); console.log(Cookies); res.writeHead(200, {‘Content-Type’: ‘text/html’}); res.write(’<html>’+ ‘<head>’+ ‘<script type=“text/javascript”>’+ ‘function load(){’+ // ‘alert(“start!”);’+ / ‘var url=location.search;’+ ‘var result=url.split("=")[1];’+ ‘if(result!=null){’+ ‘document.getElementById(“result”).value=result;’+ ‘}’+ */ ‘alert(getCookie(“result”));’+ ‘document.getElementById(“result”).value=getCookie(“result”);’+ // ‘alert(“end!”);’+ ‘}’+ ‘function getCookie(name){’+ //获取cookie ’if (document.cookie.length>0){’+ ‘c_start=document.cookie.indexOf(name + “=”);’+//查询cookie键名 ’if (c_start!=-1){’+ //查询到cookie键名 ’c_start=c_start + name.length+1;’+//查询到cookie键名 ’c_end=document.cookie.indexOf(";",c_start);’+ ‘if (c_end==-1) c_end=document.cookie.length;’+//如果只有一个cookie键值对,该方法才有效; ‘return unescape(document.cookie.substring(c_start,c_end));’+ ’}’+ ’}’+ ‘return “”;’+ ’}’+ ‘</script>’+ ‘</head>’+ ‘<body onload=“load()”>’+ ‘<input type=“text” id=“result” value=""/><br/>’+ ‘</body>’+ ‘</html>’); res.end(); });
module.exports = router;