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

我目前找到了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或知道绝对路径?


当前回答

您可以使用表单对相同的URL进行POST。

 <form  method="POST" name="refresh" id="refresh">
 <input type="submit" value="Refresh" />
 </form>

这为您提供了一个刷新当前页面的按钮。这有点烦人,因为如果用户按下浏览器刷新按钮,他们会得到一个是否要重新提交表单的消息。

其他回答

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

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

它只使用了一小部分JS。

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

你可以这样做:<a href=""> this page</a> .

但我认为它不会保留GET和POST数据。

我使用JS在jekyll网站的标签页中仅显示具有特定id的div。对于同一页面中的一组链接,您可以显示相应的元素:

function hide_others() {
    $('div.item').hide();
    selected = location.hash.slice(1);
    if (selected) {
        $('#' + selected).show();
    }
    else {
    $('div.item').show();
    }
}

链接使用如下链接:

<a href="javascript:window.location.href='/tags.html#{{ tag[0] }}-ref'; hide_others()">{{ tag[0] }}</a>

<a href=“/home” 目标=“_self”>重新加载页面</a>

使用JavaScript的一种方法是:

<a href="javascript:window.location.reload(true)">Reload</a>