Is the anchor part of a URL being sent to a web server?

后端 未结 3 1236
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-02 02:02

Say, there\'s a URL http://www.example.com/#hello

  1. Should #hello thing be sent to the web server or not, according to standards?
3条回答
  •  攒了一身酷
    2020-12-02 02:26

    The hash variables aren't sent to the web server at all.

    For instance, a request to http://www.whatismyip.org/#test from Firefox sends the follow HTTP request packet

    GET / HTTP/1.1
    Host: www.whatismyip.org
    User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language: en-us,en;q=0.5
    Accept-Encoding: gzip,deflate
    Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
    Keep-Alive: 115
    Connection: keep-alive
    Cache-Control: max-age=0
    

    You'll notice the # is nowhere to be found. Pages you see using # as a form of navigation are doing so through javascript. This parameter is accessible though the window.location.hash variable

提交回复
热议问题