在“#”后获取网址在express.js中间件请求中 [英] get url after "#" in express.js middleware request

查看:99
本文介绍了在“#”后获取网址在express.js中间件请求中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在服务器中间件上使用url(使用express.js)。我使用 req.url 但是当url从 /#some / url req.url返回时返回 / ...



req.path p>

有没有一种方法可以在express.js中的之后获取url?

解决方案

否。符号开头的网址部分永远不会发送到服务器。

中的符号用于介绍 片段标识符 。这用于链接到页面的特定部分。如果浏览器加载 /#some / url ,它将有效地加载 / ,并跳到HTML元素 id =some / url(如果存在)。这是片段标识符只与浏览器相关,因此它不会与HTTP请求一起发送。



然而可以请使用客户端Javascript读取 window.location.hash 的值,并使用XMLHttpRequest将其发送到服务器。 (查看其他Stack Overflow帖子


I need to get url on server middleware (using express.js). I use req.url but when url starts from /#some/url req.url returns /...

The same with req.path..

Is there a way to get url after # in express.js?

解决方案

No. The part of the URL starting with the # symbol is never sent to the server.

The # symbol in an URL is to introduce fragment identifier. This is used to link to a specific part of the page. If a browser loads /#some/url, it will effectively load /, and skip to the HTML element with id="some/url" (if present). This is fragment identifier is only relevant to the browser, so it is not sent with the HTTP request.

What you however can do, is using client side Javascript to read out the value of window.location.hash and send it to the server using an XMLHttpRequest. (See other Stack Overflow post.)

这篇关于在“#”后获取网址在express.js中间件请求中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆