是否有可能有一个正常的链接指向当前位置?
我目前找到了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或知道绝对路径?
是否有可能有一个正常的链接指向当前位置?
我目前找到了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">
不可否认,这涉及到javascript,但除非你的用户禁用了脚本,这是相当简单的。
其他回答
用于重载/刷新当前页面
<a href="#" onclick="window.location.reload(true);">
或使用
<a href="">refresh</a>
你可以这样做:<a href=""> this page</a> .
但我认为它不会保留GET和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="https:">link</a>
<a href="">link</a>
在这两种情况下,浏览器将相对于当前URL解析链接,导致当前URL排除了#片段。
注:
https:如果您使用的是https协议(匹配任何协议) 对于其他人来说,使用空URL可能是一个错误,https:可能更明确。 这不会重放POST请求。
如果你正在使用php/smarty模板,你可以这样做:
<a href="{{$smarty.server.REQUEST_URI}}{if $smarty.server.REQUEST_URI|strstr:"?"}&{else}?{/if}newItem=1">Add New Item</a>