search
HomeWeb Front-endJS Tutorialwindow.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:

Copy code The code is as follows:

var hash;
hash=(! window.location.hash)?"#search":window.location.hash;
window.location.hash=hash;
//Adjust the address bar address so that the forward and back buttons can use
switch (hash){
case "#search":
selectPanel("pnlSearch"); //Display the normal search panel
break;
case "#advsearch":
case "#admin ":
}

Use the statement window.location.hash=hash to adjust the address of the address bar so that the "forward" and "back" buttons in the browser can be used normally (essentially deceives 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
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
如何在Python中获取整数字面量属性而不是SyntaxError?如何在Python中获取整数字面量属性而不是SyntaxError?Aug 20, 2023 pm 07:13 PM

TogetintliteralattributeinsteadofSyntaxError,useaspaceorparenthesis.TheintliteralisapartifNumericLiteralsinPython.NumericLiteralsalsoincludesthefollowingfourdifferentnumericaltypes−int(signedintegers)−Theyareoftencalledjustintegersorints,arepositiveo

如何在Java中使用Gson重命名JSON的属性?如何在Java中使用Gson重命名JSON的属性?Aug 27, 2023 pm 02:01 PM

Gson@SerializedName注释可以序列化为JSON,并将提供的名称值作为其字段名称。此注释可以覆盖任何FieldNamingPolicy,包括可能已在Gson实例上设置的默认字段命名策略。可以使用GsonBuilder类设置不同的命名策略。语法@Retention(value=RUNTIME)@Target(value={FIELD,METHOD})public@interfaceSerializedName示例importcom.google.gson.annotations.*;

Python的dir()函数:查看对象的属性和方法Python的dir()函数:查看对象的属性和方法Nov 18, 2023 pm 01:45 PM

Python的dir()函数:查看对象的属性和方法,需要具体代码示例摘要:Python是一种强大而灵活的编程语言,其内置函数和工具为开发人员提供了许多方便的功能。其中一个非常有用的函数是dir()函数,它允许我们查看一个对象的属性和方法。本文将介绍dir()函数的用法,并通过具体的代码示例来演示其功能和用途。正文:Python的dir()函数是一个内置函数,

Win11磁盘属性未知怎么办Win11磁盘属性未知怎么办Jul 03, 2023 pm 04:17 PM

  Win11磁盘属性未知怎么办?近期Win11用户在电脑的使用中,发现系统出现提示磁盘错误的情况,这是怎么回事儿呢?而且应该如何解决呢?很多小伙伴不知道怎么详细操作,小编下面整理了Win11磁盘出错的解决步骤,如果你感兴趣的话,跟着小编一起往下看看吧!  Win11磁盘出错的解决步骤  1、首先,按键盘上的Win+E组合键,或点击任务栏上的文件资源管理器;  2、文件资源管理器的右侧边栏,找到边右键点击本地磁盘(C:),在打开的菜单项中,选择属性;  3、本地磁盘(C:)属性窗口,切换到工具选

pageXOffset属性在JavaScript中的作用是什么?pageXOffset属性在JavaScript中的作用是什么?Sep 16, 2023 am 09:17 AM

如果您想获取文档从窗口左上角滚动到的像素,请使用pageXoffset和pageYoffset属性。对水平像素使用pageXoffset。示例您可以尝试运行以下代码来了解如何在JavaScript中使用pageXOffset属性-现场演示<!DOCTYPEhtml><html>&nbsp;&nbsp;<head>&nbsp;&nbsp;&nbsp;<style>&nbsp;&nbsp;&

使用Vue.set函数实现动态添加属性的方法和示例使用Vue.set函数实现动态添加属性的方法和示例Jul 24, 2023 pm 07:22 PM

使用Vue.set函数实现动态添加属性的方法和示例在Vue中,如果我们想要动态地添加一个属性到一个已经存在的对象上,通常会使用Vue.set函数来实现。Vue.set函数是Vue.js提供的一个全局方法,它能够在添加属性时保证响应式更新。本文将介绍Vue.set的使用方法,并提供一个具体的示例。首先,在Vue中,我们通常会使用data选项来声明响应式的数据。

location.hash的用法location.hash的用法Jun 25, 2023 pm 04:58 PM

location.hash是JavaScript中的一个属性,用于获取或设置URL中的锚点部分,可以用来获取或者设置URL中的锚点部。

position有哪些属性position有哪些属性Oct 10, 2023 am 11:18 AM

position属性取值有static、relative、absolute、fixed和sticky等。详细介绍:1、static是position属性的默认值,表示元素按照正常的文档流进行布局,不进行特殊的定位,元素的位置由其在HTML文档中的先后顺序决定,无法通过top、right、bottom和left属性进行调整;2、relative是相对定位等等。

See all articles

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

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor