获取完整的 url,包括哈希后的查询字符串 [英] getting the full url including the query string after hash

查看:24
本文介绍了获取完整的 url,包括哈希后的查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取完整的URL,包括hash tag 之后的字符串参数?我试着回声

How to get the full URL including the string parameter after hash tag? I try to echo

$url = $_SERVER['REQUEST_URI'];
echo $url;

hash 标签 后面的字符串无法读取.

the string after the hash tag wont read.

推荐答案

Pekka 的评论应该是一个答案.hash 标签后的字符串参数不会发送到服务器,仅供浏览器查看.

Pekka's comment should be an answer. The string parameter after the hash tag is not sent to the server, it's for the browsers eyes only.

这意味着服务器端代码(在您的情况下为 PHP)没有此信息.客户端代码(浏览器、javascript 等)可以.

This means that serverside code (PHP, in your case) does not have this info. The clientside code (the browser, javascript, ...) does.

理想情况下,

  • ? 之后的部分是服务器信息.把你的一切服务器需要在这里
  • # 后面的部分是客户信息.把你的一切客户需要在这里.它被称为 Fragment Identifier(感谢 蒂姆).
  • the part after the ? is info for the server. Put everything your server needs here
  • the part after the # is info for the client. Put everything your client needs here. It's called the Fragment Identifier (Thanks Tim).

过去,# 后面的部分最常用于让浏览器快速滚动到页面上定义的锚点.现在,它更常用于为客户端保存状态信息.

Historically, the part after the # was most often used to have your browser quicky scroll to a defined anchor on the page. Nowadays, it is more often used to hold state information for the client.

您可以让 javascript 将此信息发送到服务器,或根据此信息执行不同的操作.AJAX 是您的朋友.

You could have javascript send this info to the server, or perform different actions based on this info. AJAX is your friend.

这篇关于获取完整的 url,包括哈希后的查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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