Home >Web Front-end >JS Tutorial >window.location.hash attribute usage instructions_javascript skills
For example, location.hash="#admin" of http://domain/#admin. A very meaningful thing can be done using this attribute value.
Many people like to bookmark web pages for easy browsing in the future. But for Ajax pages, one page is generally used to handle all transactions. That is to say, if you browse to interesting content in an Ajax page and want to save it, but there is only one address, you can open it next time. For this address, you still have to click on the web page as usual to find the page you love. In addition, the "forward" and "back" buttons on the browser will also become invalid, which is a big obstacle to use for many users who are accustomed to traditional pages.
So, how to use location.hash to solve these two problems? It's not mysterious at all.
For example, my author management system has three main functions: normal search, advanced search, and background management. I assign a hash value to them respectively: #search, #advsearch, #admin. When the page is initialized, through window.location.hash to determine the page the user needs to access, and then adjust the displayed page through javascript. For example: