简体   繁体   English

HTML锚不跟随相对链接

[英]HTML Anchor not following relative link

I have two local pages, one called Index.html https://pastebin.com/wA1Y1WC0 我有两个本地页面,其中一个称为Index.html https://pastebin.com/wA1Y1WC0

And another called biographies.html https://pastebin.com/PBeW2hz8 还有一个叫做biographies.html https://pastebin.com/PBeW2hz8

The folder structure is Project1 for the root, which contains Index.html and a folder there called members that contains biographies.html. 根目录的文件夹结构为Project1,其中包含Index.html,还有一个名为member的文件夹,其中包含biographies.html。

When I follow the link: 当我点击链接时:

 a href="members/biographies.html/#John_Lewis"

and then try 然后尝试

a href="../Index.html"

The link back to Index does not work. 回到索引的链接不起作用。

However, if I open biographies.html directly the link back to Index does work. 但是,如果我直接打开biographies.html,则指向索引的链接确实有效。 I am restricted to using relative paths, and I have tried changing the path on the biographies page multiple times, including ../Index.html AND /Project1/Index.html to no avail. 我被限制使用相对路径,并且我尝试多次更改传记页面上的路径,包括../Index.html AND /Project1/Index.html无济于事。 Can anyone give me a pointer as to why this doesn't work? 谁能给我指点一下为什么它不起作用? I've asked my teacher and we are both stumped. 我已经问过我的老师,我们俩都很沮丧。 Thanks! 谢谢!

When you serving from the file system, a link to /file.html means to look in the root of the drive for a file.html . 从文件系统提供服务时,指向/file.html的链接意味着在驱动器的根目录中查找file.html

When dealing with a webpage served by the file system, you should only use relative links. 处理文件系统提供的网页时,应仅使用相对链接。

You also had a stray slash after the file name, remove that 文件名后面也有一个斜线,将其删除

/root/Index.html => <a href="members/biographies.html#John_Lewis">
/root/members/biographies.html => <a href="../Index.html">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM