how to clear browser hash history in javascript

2019-08-16 23:54发布

问题:

I use hashchange plugin to imitate ajax navigation, i would like to create navigation throught folders, for example:

#root/ -> #root/folder -> #root/folder/subfolder -> #root/

but when i go to last #root/ in list i would like to clear previous navigation history

#root/folder -> #root/folder/subfolder

Is any ability to do that?

回答1:

Modern browsers with HTML5 support supports some manipulation via window.history. According to the docs at Mozilla Developer Network, the only supported actions are to add and replace history.

Removing browser history is thus not supported, but maybe history.replaceState() can be used to suit your needs.



回答2:

there is a way in Javascript to navigate to a new page with leaving no history in the browser hash... just use window.location.replace("any URL");... see ur browser's page navigation buttons got disabled.. and also no 'Back' option will be available in right mouse click.. Hope this will help u :)