Window. location. hash

Source: Internet
Author: User

For example, loation. href is the url of the page. However, location. hash can be used to obtain or set the tag value of the page. For example, in http: // domain/# testDemo, our location. hash is # testDemo.
The following is an online demo.
A search Section has three functions: normal search, advanced search, and background management. They respectively specify their respective hash values: # search, # advsearch, # adminboss. during page initialization. location. hash to determine the page to be accessed by the user, that is, the section to be displayed
Copy codeThe Code is as follows:
Var hash;
Hash = (! Window. location. hash )? "# Search": window. location. hash;
Window. location. hash = hash;
// Here we will explain (! Window. location. hash) What does it mean? First, if the link address in the address bar of the current page does not include those of #..., it will be blank if the value is taken directly! For example, http://www.jb51.net/directly retrieves alert (window. location. hash) // "" empty to false
// If the http://www.jb51.net # hello, world directly retrieves alert (window. location. hash) // # hello, world is converted to true
// You can use the switch to determine the following:
// Adjust the address bar to enable the forward and backward buttons.
Switch (hash ){
Case "# search ":
Show ("panel1 ");
Break;
Case "# advsearch ":
Show ("panel2 ");
Break;
Case "# adminboss ":
Show ("panel3 ");
Break;
}

Here is a sentence from someone else:
You can use the window. location. hash = hash statement to adjust the address in the address bar, so that the "Forward" and "back" buttons in the browser can be used properly (actually deceiving the browser ). Then, different panels are displayed based on the hash value (you can add the corresponding panel to favorites), which makes the browsing of Ajax pages more traditional.

Related Article

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.