Get anchor from URI

后端 未结 3 1548
野的像风
野的像风 2020-12-02 01:43

I\'m writing a JSP/Servlet and I\'m trying to get the the anchor part of the URI e.g:

blabla.rdf#mark

How do I get my mark from my request?

3条回答
  •  心在旅途
    2020-12-02 02:27

    I guess you want to make a bookmarkable Ajax web-application and you want to replace certain fragments of the DOM without reloading the full page. (Otherwise you could use query parameters.) As sfussenegger mentions, browser doesn't transmit 'anchor' to the server. The solution is on the client-side.

    Javascript window.location.hash gives the anchor information. You can append an event handler to the window.onload event which grabs window.location.hash and transmits it to the server in an Ajax XHttpRequest. You catch the response and build it into the DOM.

    Unfortunately, it's two client-server roundtrips.

    More on this at ajaxpatterns.

提交回复
热议问题