扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:Mike Brittain 来源:IBM 2007年10月21日
关键字:
function HistoryStack () { this.stack = new Array(); this.current = -1; this.stack_limit = 15; } |
HistoryStack.prototype.addResource = function(resource) { if (this.stack.length > 0) { this.stack = this.stack.slice(0, this.current + 1); } this.stack.push(resource); while (this.stack.length > this.stack_limit) { this.stack.shift(); } this.current = this.stack.length - 1; this.save(); }; |
HistoryStack.prototype.addResource = function(resource) HistoryStack.prototype.getCurrent = function () { return this.stack[this.current]; }; HistoryStack.prototype.hasPrev = function() { return (this.current > 0); }; HistoryStack.prototype.hasNext = function() { return (this.current < this.stack.length - 1 && this.current > -1); }; |
HistoryStack.prototype.go = function(increment) { // Go back... if (increment < 0) { this.current = Math.max(0, this.current + increment); // Go forward... } else if (increment > 0) { this.current = Math.min(this.stack.length - 1,this.current + increment); // Reload... } else { location.reload(); } this.save(); }; |
HistoryStack.prototype.setCookie = function(name, value) { var cookie_str = name + "=" + escape(value); document.cookie = cookie_str; }; HistoryStack.prototype.getCookie = function(name) { if (!name) return ''; var raw_cookies, tmp, i; var cookies = new Array(); raw_cookies = document.cookie.split('; '); for (i=0; i < raw_cookies.length; i++) { tmp = raw_cookies[i].split('='); cookies[tmp[0]] = unescape(tmp[1]); } if (cookies[name] != null) { return cookies[name]; } else { return ''; } }; |
HistoryStack.prototype.save = function() { this.setCookie('CHStack', this.stack.toString()); this.setCookie('CHCurrent', this.current); }; HistoryStack.prototype.load = function() { var tmp_stack = this.getCookie('CHStack'); if (tmp_stack != '') { this.stack = tmp_stack.split(','); } var tmp_current = parseInt(this.getCookie('CHCurrent')); if (tmp_current >= -1) { this.current = tmp_current; } }; |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者