How to use anchor tag to find a fixed position in the current jsp in Spring MVC?

I just want to location my html tag in my current jsp page,it means that I do not need to jump to the controller.Now I use the code,but it always jump to the controller,how to change my code? My website url is http://localhost:8888/MySpringMVC/,and I have a div called headdiv in the top.When user click the link,I want to locate it to the headdiv.My current web page url is http://localhost:8888/MySpringMVC/main/index. I want to jump to http://localhost:8888/MySpringMVC/main/index#top-container

<!--both of ways  jump to http://localhost:8888/MySpringMVC/#top-container-->
<a href="javascript:void(window.location.href='#top-container')">
<a href="#top-container">


The second thing you tried should work (<a href="#top-container">TEST</a>), works in my tests which means there is probably more to it than you wrote in your question.

Anyway, here is a small javascript solution that should work

<a href="" onclick="window.location.hash = 'top-container'; return false;">TEST</a>

Leave a Reply

Your email address will not be published. Required fields are marked *