问题描述
是否可以有正常的链接指向当前位置?
目前我找到2个解决方案,但其中一个解决方案包含JavaScript,必须知道页面的绝对路径:
< a href =#onclick =window.location.reload (真);大于1< / A>
< a href =/ foobar /> 2< / a>
< a href =#> 3(当然不起作用)< / a>
有没有这样做的方法,不使用JavaScript或不知道绝对路径?
我一直在使用:
< a href =。>连结< / a>
尚未找到无法正常工作的案例和/或浏览器。
期间表示当前路径。您还可以使用 ..
来引用当前路径上方的文件夹,例如,如果您有此文件结构:
page1.html
folder1
page2.html
然后您可以在 page2.html
写入:
< a href =../ page1.html>链接到第1页< / a>
希望有帮助!
编辑:
我不确定这种行为是否已经发生变化,或者它总是如此,但Chrome(也可能是其他人)如上面关于目录所描述的那样,而不是文件。这意味着如果你在 http://mydomain.com/foo/bar.html
你真的在目录 / foo /
和。
在 bar.html
中的href值将引用 / foo /
而不是 bar.html
将其视为浏览文件系统在终端;你永远不能 cd
到文件中:)
Is it possible to have a normal link pointing to the current location?
I have currently found 2 solutions, but one of them includes JavaScript and in the other you have to know the absolute path to the page:
<a href="#" onclick="window.location.reload(true);">1</a>
<a href="/foobar/">2</a>
<a href="#">3 (of course not working)</a>
Is there any way of doing this, without using JavaScript or knowing the absolute path?
I have been using:
<a href=".">link</a>
Have yet to find a case and/or browser where it does not work as intended.
Period means the current path. You can also use ..
to refer to the folder above the current path, for instance if you have this file structure:
page1.html
folder1
page2.html
You can then in page2.html
write:
<a href="../page1.html">link to page 1</a>
Hope that helps!
EDIT:
I'm not sure if the behavior has changed or if it was always like this, but Chrome (and maybe others) will treat periods as described above as regarding directories, not files. This means that if you are at http://mydomain.com/foo/bar.html
you are really in the directory /foo/
and a href value of .
in bar.html
will refer to /foo/
rather than bar.html
Think of it as navigating the file system in a terminal; you can never cd
into a file :)
这篇关于链接到重新加载当前页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!