URL中“#” “?” &“”号的作用

本文解析了URL中的'#'、'?'及'&'等符号的作用,包括它们如何影响浏览器行为、HTTP请求、页面重载及历史记录,并介绍了Google对URL中'#'的特殊处理方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

URL中“#” “?” &“”号的作用

一、#的意思/作用
  #代表网页中的一个位置。类似于PPT里面的页内超链接。#右面的字符,就是该位置的标识符(即 这个位置的标记)。比如,http://www.XXX.com/index.html#location就代表www.xxx.com这个网站index.html这个网页的location位置。我想这个例子应该很清楚了。浏览器读取这个URL后,会自动将‘location’位置滚动至可视区域。
  为网页位置指定标识符,有两个方法。一是使用锚点,比如<a name=”location”></a>,二是使用id属性,比如<div id=”location”>。

二、HTTP请求不包括#
  #是用来指导浏览器产生行为的,对服务器端完全没用。我的理解是帮助你锁定/定位这个页面的某个位置的。所以,HTTP请求中不包括#。
比如,访问下面的网址,http://www.XXX.com/index.html#location,浏览器实际发出的请求是这样的:

GET /index.html HTTP/1.1
Host: www.XXX.com

 

三、#后的字符
  在第一个#后面出现的任何字符,都会被浏览器解读为位置标识符。这意味着,这些字符都不会被发送到服务器端。
比如,下面URL的原意是指定一个颜色值:http://www.XXX.com/?color=#fff,但是,浏览器实际发出的请求是:

GET /?color= HTTP/1.1
Host: www.XXX.com

   

四、改变#不触发网页重载
  单单改变#后的部分,浏览器只会滚动到相应位置,不会重新加载网页。所以不要看页面有个跳的动作,就以为页面跳转或者服务器端有所响应,其实没有。
比如,从http://www.XXX.com/index.html#location1改成http://www.XXX.com/index.html#location2,浏览器不会重新向服务器请求index.html。

 

五、改变#会改变浏览器的访问历史
  每一次改变#后的部分,都会在浏览器的访问历史中增加一个记录,使用”后退”按钮,就可以回到上一个位置。这对于ajax应用程序特别有用,可以用不同的#值,表示不同的访问状态,然后向用户给出可以访问某个状态的链接。值得注意的是,上述规则对IE 6和IE 7不成立,它们不会因为#的改变而增加历史记录。

八、Google抓取#的机制
  默认情况下,Google的网络蜘蛛忽视URL的#部分。
  但是,Google还规定,如果你希望Ajax生成的内容被浏览引擎读取,那么URL中可以使用”#!”,Google会自动将其后面的内容转成查询字符串_escaped_fragment_的值。
  比如,Google发现新版twitter的URL:http://twitter.com/#!/username
  就会自动抓取另一个URL:http://twitter.com/?_escaped_fragment_=/username
  通过这种机制,Google就可以索引动态的Ajax内容。

 

AJAX = 异步 JavaScriptXML标准通用标记语言的子集)。AJAX 是一种用于创建快速动态网页的技术。

2. ?

1)连接作用:比如

http://www.xxx.com/Show.asp?id=77&nameid=2905210001&page=1

2)清除缓存:比如

http://www.xxxxx.com/index.html 
http://www.xxxxx.com/index.html?test123123

两个url打开的页面一样,但是后面这个有问号,说明不调用缓存的内容,而认为是一个新地址,重新读取。

其次,个人经验就是,用php做的页面,网址中会有类似于

?
1
https: //www..(网址路径)....php?id= ... ....

这个里面的?是php特有的一种交互方法,具体参加php的相关内容,php入门第一章应该会讲,具体忘了。

3. &

不同参数的间隔符

# ???? WEB ???? server.port=7090 server.servlet.context-path=/api #session???? 60M ???? server.servlet.session.timeout=PT60M #??favicon spring.mvc.favicon.enable=false #???? spring.mvc.throw-exception-if-no-handler-found=true spring.web.resources.add-mappings=false spring.servlet.multipart.max-file-size=20MB spring.servlet.multipart.max-request-size=20MB #数据库设置 spring.datasource.url=jdbc:mysql://118.24.147.138:3306/wangpan?serverTimezone=GMT%2B8&amp;useUnicode=true&amp;characterEncoding=utf8&amp;autoReconnect=true&amp;allowMultiQueries=true spring.datasource.username=wangpan spring.datasource.password=rootroot spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.hikari.pool-name=HikariCPDatasource spring.datasource.hikari.minimum-idle=5 spring.datasource.hikari.idle-timeout=180000 spring.datasource.hikari.maximum-pool-size=10 spring.datasource.hikari.auto-commit=true spring.datasource.hikari.max-lifetime=1800000 spring.datasource.hikari.connection-timeout=30000 spring.datasource.hikari.connection-test-query=SELECT 1 #???????? # ?????????? smtp.qq.com spring.mail.host=smtp.qq.com # ??????? spring.mail.port=465 # ??? spring.mail.username=3824245251@qq.com # spring.mail.password=ehcyxusufuulccah # ???? spring.mail.default-encoding=UTF-8 # SSL???? spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory # ?? debug???????????????? spring.mail.properties.mail.debug=true #?????? #Spring redis?? # Redis?????????0? spring.redis.database=0 spring.redis.host=118.24.147.138 spring.redis.port=6379 # ???????????????????? spring.redis.jedis.pool.max-active=20 # ??????????????????????? spring.redis.jedis.pool.max-wait=-1 # ??????????? spring.redis.jedis.pool.max-idle=10 # ??????????? spring.redis.jedis.pool.min-idle=0 # ?????????? spring.redis.timeout=2000 #项目目录 project.folder=/www/wangpan/ # log.root.level=debug #内部端口 inner.api.appKey=wangpan inner.api.appSecret=wangpan_key #web端口 web.api.url=http://118.24.147.138:7090 #管理员id admin.emails=961285867@qq.com #是否是开发环境 dev=false ##qq????## qq.app.id=12333 qq.app.key=2222222 qq.url.authorization=https://graph.qq.com/oauth2.0/authorize?response_type=code&amp;client_id=%s&amp;redirect_uri=%s&amp;state=%s qq.url.access.token=https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&amp;client_id=%s&amp;client_secret=%s&amp;code=%s&amp;redirect_uri=%s qq.url.openid=https://graph.qq.com/oauth2.0/me?access_token=%S qq.url.user.info=https://graph.qq.com/user/get_user_info?access_token=%s&amp;oauth_consumer_key=%s&amp;openid=%s qq.url.redirect=http://wangpan.wuhancoder.com/qqlogincalback springboot的配置文件,部署到服务器上,有什么错误吗
最新发布
05-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值