是否有可能有一个正常的链接指向当前位置?

我目前找到了2个解决方案,但其中一个包括JavaScript,在另一个你必须知道页面的绝对路径:

<a href="#" onclick="window.location.reload(true);">1</a>
<a href="/foobar/">2</a>
<a href="#">3 (of course not working)</a>

有没有办法做到这一点,而不使用JavaScript或知道绝对路径?


当前回答

试试这个

<a href="javascript:window.location.href=window.location.href">

其他回答

完全幂等的url,保留路径,参数和锚。

 <a href="javascript:"> click me </a>

它只使用了一小部分JS。

编辑:这不会重新加载页面。它是一个没有任何作用的链接。

<a href=".">refresh current page</a>

或者如果你想传递参数:

<a href=".?curreny='usd'">refresh current page</a>

两个选择:

<a href="https:">link</a>
<a href="">link</a>

在这两种情况下,浏览器将相对于当前URL解析链接,导致当前URL排除了#片段。

注:

https:如果您使用的是https协议(匹配任何协议) 对于其他人来说,使用空URL可能是一个错误,https:可能更明确。 这不会重放POST请求。

<a href="/">Same domain, just like refresh</a>

似乎只有当你的网站是index.html, index.htm或index.php(任何默认页面)。

但似乎。是同样的东西,更容易被接受吗

<a href=".">Same domain, just like refresh, (more used)</a>

两者工作完美的Chrome浏览器时,域名都是http://和https://

其他答案都不会保留任何查询字符串值。试一试

<a href="javascript:window.location.href=window.location.href">

不可否认,这涉及到javascript,但除非你的用户禁用了脚本,这是相当简单的。