惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
Cloudbric
Cloudbric
P
Palo Alto Networks Blog
T
Threatpost
T
Tor Project blog
T
Tenable Blog
AWS News Blog
AWS News Blog
Project Zero
Project Zero
L
LangChain Blog
Cyberwarzone
Cyberwarzone
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
C
CERT Recently Published Vulnerability Notes
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Latest
Security Latest
云风的 BLOG
云风的 BLOG
I
Intezer
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
MongoDB | Blog
MongoDB | Blog
aimingoo的专栏
aimingoo的专栏
K
Kaspersky official blog
Jina AI
Jina AI
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Recorded Future
Recorded Future
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Secure Thoughts
TaoSecurity Blog
TaoSecurity Blog
P
Privacy & Cybersecurity Law Blog
P
Proofpoint News Feed
MyScale Blog
MyScale Blog
IT之家
IT之家
Forbes - Security
Forbes - Security
The Hacker News
The Hacker News
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
Y
Y Combinator Blog

博客园 - 轻松

css div 垂直居中 How to create custom methods for use in spring security expression language annotations How to check “hasRole” in Java Code with Spring Security? Android 显示/隐藏 应用图标 Android 当媒体变更后,通知其他应用重新扫描 Dynamically loading an external JavaScript or CSS file android 脸部抠图 IIS + TOMCAT 注意事项 textbox icon jquery 插件 让IE支持HTML5的Canvas vba 生成euc文件的方法 - 轻松 - 博客园 数值项目的格式化 - 轻松 - 博客园 [原创]让Allvidoes插件支持 优酷(www.youku.com)的视频 ORACLE ERROR CODE代表的意思 http://hi.baidu.com/czh0221/blog/item/9f0447e719644a2ab83820c6.html JAVA 调用Web Service的方法 xampp-control中启动Apache时80断口被占用的错误 asp.net mail java获取运行的jar(class)文件的路径
[转]利用location的hash值来解决Ajax两大难题
轻松 · 2009-02-18 · via 博客园 - 轻松

location是javascript里边管理地址栏的内置对象,比如location.href就管理页面的url,用 location.href=url就可以直接将页面重定向url。而location.hash则可以用来获取或设置页面的标签值。比如http: //domain/#admin的location.hash="#admin"。利用这个属性值可以做一个非常有意义的事情。

很多人都喜欢收藏网页,以便于以后的浏览。不过对于Ajax页面来说的话,一般用一个页面来处理所有的事务,也就是说,如果你浏览到一个 Ajax页面里边有意思的内容,想将它收藏起来,可是地址只有一个呀,下次你打开这个地址,还是得像以往一样不断地去点击网页,找到你钟情的那个页面。另 外的话,浏览器上的“前进”“后退”按钮也会失效,这于很多习惯了传统页面的用户来说,是一个很大的使用障碍。

那么,怎么用location.hash来解决这两个问题呢?其实一点也不神秘。

比如,我的作者管理系统,主要功能有三个:普通搜索、高级搜索、后台管理,我分别给它们分配一个hash值:#search、 #advsearch、#admin,在页面初始化的时候,通过window.location.hash来判断用户需要访问的页面,然后通过 javascript来调整显示页面。比如:

var hash;

hash=(!window.location.hash)?"#search":window.location.hash;

window.location.hash=hash;     //调整地址栏地址,使前进、后退按钮能使用

switch(hash){

  case "#search":

    selectPanel("pnlSearch");  //显示普通搜索面板

    break;

  case "#advsearch":

    ...

  case "#admin":

    ...

}

通过window.location.hash=hash这个语句来调整地址栏的地址,使得浏览器里边的“前进”、“后退”按钮 能正常使用(实质上欺骗了浏览器)。然后再根据hash值的不同来显示不同的面板(用户可以收藏对应的面板了),这就使得Ajax页面的浏览趋于传统化 了。