javascripthtmljqueryurl-fragment

How to reload page when hash.location are the same javascript


I have i button that puts the hash (#feed) and i want when i am on this page with that has, when click the button again it reloads the page with that hash(#feed).

Is there some way to do that?


Solution

  • You can trigger an onclick event and refresh the page with location.reload(); :

    function reload(e){
        e.preventDefault();
        location.href = e.target.href;
        location.reload();
    }
    a {
        display: block;
        width: 100px;
        height: 25px;
        background: lightgray;
        text-align: center;
        border-radius: 5px;
    }
    <a href="#feed" onclick="reload(event);">ok</a>