location.hash来保持页面状态
/*本例是为了在客户端页面返回时保存状态,采用hash值记录的模式,为了使用方便所写的存取hash值的库,时间仓促,望指出错误。*/
var pageStateHash = {
hashArray: [],
getHashArray: function() {
var _self = this;
if (window.location.hash.replace('#','') != '') {
_self.hashArray = window.location.hash.replace('#','').split('&');
}
},
applyHash: function() {
var _self = this;
window.location.hash = '#' + _self.hashArray.join('&');
},
hashIndex: function(key) {
var _self = this;
var ret = -1;
_self.getHashArray();
for (var i in _self.hashArray) {
var item = _self.hashArray[i].split('=');
var length = item.length;
if (length == 2 && item[0] == key) {
ret = i;
}
}
return ret;
},
set: function(key, value) {
var _self = this;
var hashIndex = _self.hashIndex(key);
console.log('hash index = '+hashIndex);
if (hashIndex == -1) {
_self.hashArray.push(key + '=' + value);
} else {
_self.hashArray[hashIndex] = key + '=' + value;
} _self.applyHash();
},
get: function(key) {
var _self = this;
var hashIndex = _self.hashIndex(key);
if (hashIndex == -1) {
return '';
} else if (_self.hashArray[hashIndex].split('=').length == 2) {
return _self.hashArray[hashIndex].split('=')[1];
}
}
};
/*pageStateHash.set('cate1', '8');
pageStateHash.set('cate2', '9');
console.log('get cate2 index:' +pageStateHash.get('cate2'));*/
location.hash来保持页面状态的更多相关文章
- 巧用location.hash保存页面状态
在我们的项目中,有大量ajax查询表单+结果列表的页面,由于查询结果是ajax返回的,当用户点击列表的某一项进入详情页之后,再点击浏览器回退按钮返回ajax查询页面,这时大家都知道查询页面的表单和结果 ...
- 使用location.hash保存页面状态
hash 属性是一个可读可写的字符串,该字符串是 URL 的锚部分(从 # 号开始的部分). 语法 location.hash 在我们的项目中,有大量ajax查询表单+结果列表的页面,由于查询结果是a ...
- 学习笔记:location.hash和history.pushState()
在浏览器中改变地址栏url,将会触发页面资源的重新加载,这使得我们可以在不同的页面间进行跳转,得以浏览不同的内容.但随着单页应用的增多,越来越多的网站采用ajax来加载资源.因为异步加载的特性,地址栏 ...
- 前端 JS 原生 javascript 和 location.hash 实现一个单页应用的路由 router
开篇日常立个flag-- 前言 最近在做一些应用,类似于单页应用,想实现类似于 Vue 路由的效果. 但是个人 Vue 基础四舍五入约等于无,而且看着 Vue-router 吃力+用不起来(因为我的项 ...
- 简单使用location.hash的方法 ,怎么做,有什么用? 简单的js路由页面方法。
hash 属性是一个可读可写的字符串,该字符串是URL的锚部分(从#号开始的部分).语法location.hash刚开始我真不知道hash有什么用,直到我在项目中遇上一个最大的问题.而且很恶心的体验 ...
- window.location.hash 页面跳转,精确定位,实例展示:
window.location.hash 页面跳转,精确定位,实例展示: (1).index.phtml,页面用于传参 <script id="bb_list_template&quo ...
- window.location.hash(hash应用)---跳转到hash值制定的具体页面
location是javascript里边管理地址栏的内置对象,比如location.href就管理页面的url,用location.href=url就可以直接将页面重定向url.而location. ...
- js 利用iframe和location.hash跨域解决的方法,java图片上传回调JS函数跨域
奶奶的:折腾了我二天,最终攻克了!网上有非常多样例. 但跟我的都不太一样,费话不多说了,上图 上代码: IE ,firefix,chrome 測试通过 js :这个主页面,部分代码, functi ...
- window.location.hash 使用说明
本文给大家详细汇总了关于window.location.hash的知识点,属性以及用法等等,非常的实用,并附上了例子,有需要的小伙伴可以参考下. location是javascript里边管理地址 ...
随机推荐
- React事件属性
一.简介 二.滚动例子,滚动改变颜色 <!DOCTYPE html> <html lang="zh-cn"> <head> <meta c ...
- android-exploitme(一):生成apk
exploitme是一个国外的android安全测试环境,http://securitycompass.github.io/AndroidLabs/index.html,通过它可以学习一些基本的测试方 ...
- C 中数组和指针的区别
联系: 1,一个通过数组和下标实现的表达式可等价地通过指针和偏移量实现. 2,当数组名传递给一个函数时,实际上传递的是该数组第一个元素的地址. 区别: 1,指针是一个变量,因此,在C语言中,语句pa= ...
- Spring-Boot初始篇
Spring Boot 项目旨在简化创建产品级的 Spring 应用和服务.你可通过它来选择不同的 Spring 平台.可创建独立的 Java 应用和 Web 应用,同时提供了命令行工具来允许 ‘sp ...
- 构建ASP.NET MVC5+EF6+EasyUI 1.4.3+Unity4.x注入的后台管理系统
开篇:从50开始系统已经由MVC4+EF5+UNITY2.X+Quartz 2.0+easyui 1.3.4无缝接入 MVC5+EF6+Unity4.x+Quartz 2.3 +easyui 1.4. ...
- Oracle ->> 生成测试数据
declare v_exists_table number; begin select count(*) into v_exists_table from all_tables where table ...
- Algorithm: cartesian tree
http://baike.baidu.com/link?url=XUt5fXQ-jtFBM0UdKiGA41_NWFvdFSYwVsy4SVvCRRuEBvNkLfT9TgOtzsXvaOT9nuq_ ...
- VMware VMware各版本
VMware各版本 一.VMware vSphere5: VMware vSphere5 取代原 VMware ESX 二.VMware ESXI/VMware Citrix/VMware XenS ...
- leetcode:Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...
- STL笔记(6)标准库:标准库中的排序算法
STL笔记(6)标准库:标准库中的排序算法 标准库:标准库中的排序算法The Standard Librarian: Sorting in the Standard Library Matthew A ...