Home Web Front-end JS Tutorial window.location.hash usage instructions_javascript skills

window.location.hash usage instructions_javascript skills

May 16, 2016 pm 06:16 PM
hash location

For example, location.href is the URL of the page. But location.hash can get or set the tag value of the page. For example, our location.hash in http://domain/#testDemo is #testDemo
The following is a reference to an online demo
A search section with three functions: normal search, advanced search, and background management. Specify their respective hash values: #search, #advsearch, #adminboss. When the page is initialized, it is judged by window.location.hash The page that the user needs to visit is the section that will be displayed

Copy the code The code is as follows:

var hash;
hash = (!window.location.hash)?"#search":window.location.hash;
window.location.hash = hash;
//Here we explain (! What does window.location.hash) mean? First of all, if the link address in the address bar of the current page does not contain #...., if the value is taken directly, it will be empty! For example, in this example, http://www. jb51.net/Directly take alert(window.location.hash)//""empty is converted into boolean value is false
// If http://www.jb51.net#hello,world directly take alert(window. location.hash)//#hello,world is converted into a boolean value of true
//The following can be judged by switch
//Adjust the address bar address so that the forward and back buttons can use
switch( hash){
case "#search":
show("panel1");
break;
case "#advsearch":
show("panel2");
break ;
case "#adminboss":
show("panel3");
break;
}

The following quote from someone else:
Through window The statement .location.hash=hash is used to adjust the address in the address bar so that the "forward" and "back" buttons in the browser can be used normally (essentially deceiving the browser). Then different panels are displayed based on different hash values ​​(the user can collect the corresponding panels), which makes the browsing of Ajax pages more traditional.
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to implement Redis Hash operation in php How to implement Redis Hash operation in php May 30, 2023 am 08:58 AM

Hash operation //Assign values ​​to fields in the hash table. Returns 1 on success and 0 on failure. If the hash table does not exist, the table will be created first and then the value will be assigned. If the field already exists, the old value will be overwritten. $ret=$redis->hSet('user','realname','jetwu');//Get the value of the specified field in the hash table. If the hash table does not exist, return false. $ret=$redis->hGet('user','rea

Analysis of location configuration examples in Nginx server Analysis of location configuration examples in Nginx server May 24, 2023 pm 02:05 PM

First, let me briefly introduce the types of location and matching rules, using the example of nginxwiki as an example: location=/{#matchesthequery/only.[configurationa]}location/{#matchesanyquery,sinceallqueriesbeginwith/,butregular#expressionsandanylongerconventionalblockswillbe#matchedfirst.[ configurationb]}location^~/im

How to intercept uri in nginx location How to intercept uri in nginx location May 18, 2023 pm 12:07 PM

Note: The root and aliasroot instructions in location only set the search root to the directory set by root, that is, the uri will not be truncated. Instead, the original uri will be used to jump to the directory to find the file. The aias instruction will truncate the matching uri, and then Use the path set by alias plus the remaining uri as a sub-path to find the uri of proxy_pass in location. If the url of proxy_pass does not have uri, if the tail is "/", the matching uri will be truncated. If the tail is not "/", then Will not truncate the matching uri if the proxy_pass url contains uri

Laravel development: How to generate password hash using Laravel Hash? Laravel development: How to generate password hash using Laravel Hash? Jun 17, 2023 am 10:59 AM

Laravel is currently one of the most popular PHP web frameworks, providing developers with many powerful features and components, among which LaravelHash is one of them. LaravelHash is a PHP library for password hashing that can be used to keep passwords secure and make your application's user data more secure. In this article, we will learn how LaravelHash works and how to use it to hash and verify passwords. Prerequisite knowledge in learning Lara

How to configure location and rewrite rules in Nginx How to configure location and rewrite rules in Nginx May 18, 2023 pm 12:25 PM

Location tutorial example: location=/{#Exact match/, the host name cannot be followed by any string [configurationA]}location/{#Because all addresses begin with /, this rule will match all requests#But regular and the longest string will be matched first [configurationB]}location/documents/{#Match any address starting with /documents/. After matching, continue to search downwards#Only when the subsequent regular expression is not matched, This article will use [configurationC]}location~/document

How to configure location in Nginx server How to configure location in Nginx server May 14, 2023 pm 07:16 PM

Grammar location[=|~|~*|^~]/uri/{...} Rule=: Indicates exact uri matching (interested students can take a look at the difference between url and uri)~: Indicates case-sensitive Regular matching~*: Indicates case-insensitive regular matching!~&&!~*: Indicates case-insensitive non-matching regular and case-insensitive non-matching regular /: Universal matching, any request will be matched to the location match The target location matching test only uses the request uri part, not the parameter part. (Reason: There are too many ways to write parameters and cannot be matched accurately) On the premise of multiple location configurations in the location matching sequence,

What is the matching logic of Server and Location in Nginx? What is the matching logic of Server and Location in Nginx? May 12, 2023 am 11:10 AM

Server matching logic When nginx determines which server block to execute a request, it mainly focuses on the listen and server_name fields in the server block. The listen command listen field defines the IP and port of the server response. If the listen field is not explicitly configured, the default listening 0.0.0.0:80 (root) or 0.0.0.0:8080 (non-root) listen can be configured as: a combination of ip and port, a single ip, listening on port 80 by default, a single port, and listening on all ip interfaces by default A unixsocket path where the last entry is usually only used in different

What are the Nginx Location directive URI matching rules? What are the Nginx Location directive URI matching rules? May 14, 2023 pm 11:58 PM

1. Introduction The location directive is the core configuration of the http module. It receives requests sent by users based on predefined URL matching rules. Based on the matching results, the request is forwarded to the backend server. Illegal requests are directly rejected and return 403. 404, 500 error handling, etc. 2. Location instruction syntax location[=|~|~*|^~|@]/uri/{…} or location@name{…} 3. URI matching mode The location instruction is divided into two matching modes: 1> Ordinary characters String matching: rules starting with = or without leading characters (~) 2> Regular matching: starting with ~ or ~* indicates regular matching, ~*

See all articles