是否有可能有一个正常的链接指向当前位置?
我目前找到了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">
其他回答
你可以这样做:<a href=""> this page</a> .
但我认为它不会保留GET和POST数据。
<a href="/">单击me刷新页面</a>
< a href = "吗?">点击我重新加载页面</a> .
试试这个
<a href="javascript:window.location.href=window.location.href">
两个选择:
<a href="https:">link</a>
<a href="">link</a>
在这两种情况下,浏览器将相对于当前URL解析链接,导致当前URL排除了#片段。
注:
https:如果您使用的是https协议(匹配任何协议) 对于其他人来说,使用空URL可能是一个错误,https:可能更明确。 这不会重放POST请求。
只要添加target="_blank",链接就会打开一个新的页面,保持原来的页面。