[英]How to use anchor tag in URL?
I want to load certain part of a page when the page loads. 我想在页面加载时加载页面的某些部分。 Like i have a image on the top and a form below. 就像我在顶部有一个图像和下面的表格。 So when my user clicks on the image in previous page the user should see the form directly below and not the image. 因此,当我的用户点击上一页中的图像时,用户应该直接看到下面的表单,而不是图像。
What i tried. 我尝试了什么。
window.scroll
window.scrollTo
window.scrollBy
Element.scrollintoview
None of them worked. 他们都没有工作。
But then i tried with anchor tag and it worked like i tried 但后来我尝试使用锚标签,它就像我试过的那样工作
http://localhost:8080/myproject#anchorId (worked fine)
But if i do something like this 但如果我做这样的事情
http://localhost:8080/myproject/test.jsp#anchorId (does not work)
Please guide how can i use anchor tag when i have jsp in URL 请指导我在URL中使用jsp时如何使用锚标记
You can do something like: 你可以这样做:
element = document.getElementById("divFirst")
alignWithTop = true;
element.scrollIntoView(alignWithTop);
Or you can: 或者你可以:
Set a <base>
tag in your document. 在文档中设置<base>
标记。 All identifier links are also relative to it. 所有标识符链接也与其相关。 If this is true, then you need to change your identifier links from 如果是这样,那么您需要更改标识符链接
<a href="#name">
to 至
<a href="${pageContext.request.requestURI}#name">
See also: Is it recommended to use the <base>
html tag? 另请参阅: 是否建议使用<base>
html标记?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.