VaR go = Document. queryselector (". Go "),
Back = Document. queryselector (". Back "),
Url = Window. Location. href;
W. addhandler (go, "click", function (){
History. Go (1 );
});
W. addhandler (back, "click", function (){
History. Go (-1 );
});
W. addhandler (window, "hashchange", function (){
W. Log (window. Location. href );
// Pushstate creates a false URL at the front end and corresponds to the real URL at the background
History. pushstate ({Name: URL. Hash}, "new page ");
// The status information of the first parameter is used to initialize the page.
// The title of the new status of the second parameter (Kong can be set without a browser)
// The relative URL of the third parameter corresponds to the actual URL of the server
});
// Use hashchange to write the change to history without opening a new page, so that the change can still be effective after moving backward.
// Triggered when the status changes, including forward and backward. Here, you can operate the page to load the content of the server's real URL.
W. addhandler (window, "popstate", function (event ){
VaR state = event. State;
Alert (State. Name );
If (state) {// The State is blank when the first page is loaded
// Do something
}
});
// Replacestate will not rewrite the history state stack, but will only rewrite the current State to change the State obtained by popstate.
History. replacestate ({name: "replace"}, "Haha ");
Window. Location. href = URL + "# DSD ";
History Status Management