History Status Management

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.