Monstr92
Monstr92

Reputation: 404

Rewrite URL using JS Window.Location without reloading the page?

Is it possible to rewrite a pages URL without having the page reload it self via Javascript when setting the window.location to slash?

For example, I have an a href item that sets the link to #item1

<a href="#item1">

and then it's linked up via to a js class that pulls a popup open and when the popups close button is pressed I then rewrite the url to

window.location = "/#";

Is it possible to rewrite the url to so that there is no hash remaining?

window.location = "/";

Without having the webpage reload it self since / means home?

Upvotes: 1

Views: 1991

Answers (2)

oleksii.svarychevskyi
oleksii.svarychevskyi

Reputation: 1106

var stateObj = { home: "home" };
history.pushState(stateObj, "home", "/");

Upvotes: 1

Related Questions