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

201 Views Asked by At

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?

1

There are 1 best solutions below

0
On BEST ANSWER

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>