window.location.hash属性介绍
来源:互联网 发布:手机淘宝改好评步骤 编辑:程序博客网 时间:2024/05/21 13:39
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":
}
hash=(!window.location.hash)?"#search":window.location.hash;
window.location.hash=hash;
//调整地址栏地址,使前进、后退按钮能使用
switch(hash){
case "#search":
selectPanel("pnlSearch"); //显示普通搜索面板
break;
case "#advsearch":
case "#admin":
}
0 0
- 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属性介绍
- window.location.hash属性介绍
- window.location.hash属性介绍
- window.location.hash属性介绍
- window.location.hash属性介绍
- window.location.hash属性介绍
- Window.location.hash属性介绍
- Linux下生成ubi文件
- 小菜鸟的第一篇博客
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] D. "Or" Game (贪心法)
- 两个链表的交叉
- MATLAB数学建模(3)-非线性规划
- window.location.hash属性介绍
- encode_utf8 把字符编码成字节 微信例子
- Android开源项目 优秀项目
- shell编写简单的CGI脚本
- 指令流水线的吞吐率
- 在gridview上显式系统联系人的信息
- JSP的内置对象
- 动态规划--最小调整代价
- java.lang.ClassNotFoundException