简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM