window.location.hash
来源:互联网 发布:小城生活 知乎 编辑:程序博客网 时间:2024/06/05 14:46
window.location.hash属性介绍
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来调整显示页面。比如:
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页面的浏览趋于传统化了。
转载源地址:http://www.cnblogs.com/china-aspx/archive/2008/04/20/1162597.html
- window.location.hash解析
- window.location.hash解析
- window.location.hash详解
- window.location.hash详解
- 有关window.location.hash
- window.location.hash
- window.location.hash 使用说明
- window.location.hash
- window.location.hash 使用说明
- window.location.hash
- window.location.hash 使用说明
- window.location.hash属性介绍
- AJAX Navigation (window.location.hash)
- window.location.hash属性介绍
- window.location.hash使用总结
- window.location.hash属性介绍
- window.location.hash属性介绍
- window.location.hash常用方法
- [题解]hdu1255 覆盖的面积
- java.io.IOException: Invalid keystore format
- Cookies 和 Session的区别
- 你真的了解事务吗?
- Tomcat配置优化
- window.location.hash
- request和response响应头
- PAT乙级(Basic Level)练习题-NowCoder数列
- oracle 用lambda表达式查询和与原生态sql查询出来的结果不一样。
- jQuery判断页面滚动方向
- 泛型应用于集合
- 梯度下降算法优化综述An overview of gradient descent optimization algorithms
- 最近处理了很多服务端 相关的报错,总结记录
- c++的*与&简单总结