How to get the #fragment identifier part of an URL

后端 未结 1 1703
旧巷少年郎
旧巷少年郎 2021-01-19 12:36

In Phoenixframework I want to know full URL path that is being requested so I tried to use <%= @conn.request_path %>. The problem is that I\'m requesting

1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-19 13:09

    The fragment is not available on the server side.

    From RFC2396

    When a URI reference is used to perform a retrieval action on the identified resource, the optional fragment identifier, separated from the URI by a crosshatch ("#") character, consists of additional reference information to be interpreted by the user agent after the retrieval action has been successfully completed. As such, it is not part of a URI, but is often used in conjunction with a URI.

    You can access it in JavaScript with window.location.hash.

    http://www.mikeduncan.com/?s=named+anchors (from Get anchor part of URL in controller in Ruby on Rails) Is a good resource on the topic.

    0 讨论(0)
提交回复
热议问题