Sam Tyurenkov
Sam Tyurenkov

Reputation: 440

How do I force page reload in a link with hash sign?

I have a link with hash sign:

href="/#something"

How do I enable page reload when its clicked?

Is it only possible with js?

Upvotes: 0

Views: 189

Answers (1)

Okoch
Okoch

Reputation: 465

You have to listen to the HashChangeEvent and add a query param (like a timestamp) to the location search object:

function locationHashChanged() {
    var dstringquery = `d=${new Date().getTime()}`;
    location.search = location.search.length === 0 ?  dstringquery : (location.search + '&' + dstringquery);
}

window.onhashchange = locationHashChanged;

Upvotes: 2

Related Questions