history.js README

The project's README from github.com/browserstate/history.js. As one markdown file: README.md.

Memo

While there are some legitimate bugs and differences in state handling even in modern browsers, they are relatively small enough now that you can just use the native HTML5 History API. If you intend to support legacy browsers, then History.js is your bet.

This notice is here as History.js does not receive enough funding to be maintained, so it exists only in legacy condition for legacy browsers. Perhaps it still works for modern browsers, but it could really do with maintenance. Maintenance is very difficult as the library requires manual testing in HTML5 and HTML4 modes, and for each adapter, and for each browser. So that means 2^(# of adapters)^(# of browsers and their versions) tests that need to be run by a human. Tests need to be run by a human as certain failures require browser interactions, such as navigating from the test suite to a different domain and back again, or clicking the physical back buttons, or checking if the physical back buttons actually work. This takes a lot of time.

Despite History.js being one of the most popular JavaScript libraries there is, and has been used by even multi-million-user companies in its time - the reality of economy and company practices seems to be that companies prefer to fork their own internal versions and fix locally with their own devs rather than fund open-source maintainers what they would pay their own devs to make things better for everyone, including themselves, which would be cheaper - but no, that would require too many tiers of company approval that don't understand the need.

As such, if you are an open-source developer, I'd recommend just working on open-source projects that are paid for by your own consulting work or your own company (e.g. every successful open-source project). As otherwise, when they become popular, you better hope they are easily maintainable and testable, otherwise the cost of maintenance is higher than the free time of the maintainers.

So with all that said, this repo still exists for archival purposes, legacy browsers, and a hub for anarachistic issue & fork maintenance.

Cheers, Benjamin Lupton, founder of Bevry, creator of History.js

Welcome to History.js
v1.8b2, June 22 2013

Slack community badge Patreon donate button Gratipay donate button Flattr donate button PayPal donate button Bitcoin donate button Wishlist browse button

News

History

See the HISTORY.md file for a detailed list of features, changes, solved issues and bugs

Involve

Please create an issue if something doesn't work or if there is a browser specific bug. I'll try to fix it as soon as possible. Please send me your Pull requests if you have a nice solution! I'm also going to review old issues in balupton's repository and try to solve them too.

Aims

Quick Install

Via Ajaxify Script

To ajaxify your entire website with the HTML5 History API, History.js and jQuery the Ajaxify script is all you need. It's that easy.

Via Ajaxify Extension

If you don't have access to your server, or just want to try out the Ajaxify script first, you can install the History.js It! Google Chrome Extension to try out History.js via Ajaxify on select websites without actually installing History.js/Ajaxify on your server.

Via Ruby On Rails Gem

If you are using Rails, then the easiest way for you to try History.js would be to use Wiselinks gem. Wiselinks integrates into Rails application and allows you to start using History.js with three lines of code.

Direct Install

Working with History.js directly

(function(window,undefined){

	// Bind to StateChange Event
	History.Adapter.bind(window,'statechange',function(){ // Note: We are using statechange instead of popstate
		var State = History.getState(); // Note: We are using History.getState() instead of event.state
	});

	// Change our States
	History.pushState({state:1}, "State 1", "?state=1"); // logs {state:1}, "State 1", "?state=1"
	History.pushState({state:2}, "State 2", "?state=2"); // logs {state:2}, "State 2", "?state=2"
	History.replaceState({state:3}, "State 3", "?state=3"); // logs {state:3}, "State 3", "?state=3"
	History.pushState(null, null, "?state=4"); // logs {}, '', "?state=4"
	History.back(); // logs {state:3}, "State 3", "?state=3"
	History.back(); // logs {state:1}, "State 1", "?state=1"
	History.back(); // logs {}, "Home Page", "?"
	History.go(2); // logs {state:3}, "State 3", "?state=3"

})(window);

How would the above operations look in a HTML5 Browser?

  1. www.mysite.com
  2. www.mysite.com/?state=1
  3. www.mysite.com/?state=2
  4. www.mysite.com/?state=3
  5. www.mysite.com/?state=4
  6. www.mysite.com/?state=3
  7. www.mysite.com/?state=1
  8. www.mysite.com
  9. www.mysite.com/?state=3

Note: These urls also work in HTML4 browsers and Search Engines. So no need for the hashbang (#!) fragment-identifier that google "recommends".

How would they look in a HTML4 Browser?

  1. www.mysite.com
  2. www.mysite.com/#?state=1&_suid=1
  3. www.mysite.com/#?state=2&_suid=2
  4. www.mysite.com/#?state=3&_suid=3
  5. www.mysite.com/#?state=4
  6. www.mysite.com/#?state=3&_suid=3
  7. www.mysite.com/#?state=1&_suid=1
  8. www.mysite.com
  9. www.mysite.com/#?state=3&_suid=3

Note 1: These urls also work in HTML5 browsers - we use replaceState to transform these HTML4 states into their HTML5 equivalents so the user won't even notice :-)

Note 2: These urls will be automatically url-encoded in IE6 to prevent certain browser-specific bugs.

Note 3: Support for HTML4 browsers (this hash fallback) is optional - why supporting HTML4 browsers could be either good or bad based on my app's use cases

What's the deal with the SUIDs used in the HTML4 States?

Is there a working demo?

Download & Installation

Note: If you want to only support HTML5 Browsers and not HTML4 Browsers (so no hash fallback support) then just change the /html4+html5/ part in the urls to just /html5/. See Why supporting HTML4 browsers could be either good or bad based on my app's use cases

Get Updates

Get Support

Thanks! every bit of help really does make a difference!

Browsers: Tested and Working In

HTML5 Browsers

HTML4 Browsers

Exposed API

Functions

States

Adapter

Navigation

Debug

Options

Events

Known Issues

Notes on Compatibility

License

Licensed under the New BSD License
Copyright © 2014+ Bevry Pty Ltd [email protected]
Copyright © 2011-2013 Benjamin Arthur Lupton [email protected]

For support see the Getting Support section.

history.js (browserstate/history.js)

Searching Database…

这是做什么的?一个 JavaScript 库,让 HTML5 的 History/State API(pushState、replaceState、onpopstate)在所有浏览器中表现一致:支持 HTML5 的浏览器使用真实 URL,老的 HTML4 浏览器则退回到基于 hash 的方式。
它是用来搭建应用的框架,还是可以加到现有页面里的库?是一个拿来即用的库:只需引入一个打包好的脚本文件,然后在自己的代码里调用 History.pushState / History.replaceState。适配器会把它接入页面已经在用的框架(jQuery、MooTools、Prototype)。
我怎么把它加到我的网站上?下载 tar.gz 或 zip,上传到你的网站服务器,然后用 script 标签引入与你适配器匹配的构建版本,或者用 Ajaxify 脚本一次性把整个网站 ajax 化。还有一个名为 'History.js It!' 的 Chrome 扩展,不用动服务器就能先试用。
它需要 jQuery 吗,还是可以独立运行?它可以独立运行(包含一个'用于其他所有情况'的构建版本),另外还提供 jQuery v1.3+、MooTools v1.3+、Zepto v0.5+、Dojo v1.8+、ExtJS 和 Right.js v2.2+ 的适配器。选一个与你页面框架匹配的文件即可。
它还在维护吗?我该在现代浏览器里用它吗?实际上不再维护了:作者表示现代浏览器的原生 HTML5 History API 已经足够好,这个库只'以遗留状态为遗留浏览器保留'。最后一次发布的版本是 v1.8b2,2013 年 6 月。
现在它适合谁用?需要在老浏览器上也能正常使用历史记录和整洁 URL 的网页开发者。如果只针对现代浏览器,README 建议直接用原生 API。
它能在哪些浏览器里运行?HTML5 模式:Firefox 4+、Chrome 8+、Opera 11.5+、Safari 5+、iOS Safari 4.3+。HTML4 hash 回退模式:IE 6-9(10 属于尝试性支持)、Firefox 3、Opera 10/11.0、Safari 4、较老的 iOS。它是纯 JavaScript,所以操作系统无关紧要。
在老浏览器里 URL 是什么样子?HTML4 浏览器会看到类似 www.mysite.com/#?state=2&suid=2 的 hash URL,其中 SUID 后缀把 hash 与你的状态数据和标题关联起来。如果 HTML5 浏览器打开这个链接,History.js 会悄悄把它升级成对应的、不带 hash 的整洁 URL。
我还需要用 Google 的 hashbang(#!)技巧来配合搜索引擎吗?不需要。整洁的 ?state= URL 在 HTML4 浏览器和搜索引擎里也能用,所以不再需要 hashbang 片段标识符。
它的 API 长什么样?是 HTML5 风格的调用:History.pushState(data,title,url)、History.replaceState(data,title,url) 和 History.getState(),另外还提供后退/前进/go 导航、一个不依赖框架的 History.Adapter,以及 window.onstatechange 事件。
有没有演示或测试可以看?有。下载之后,在浏览器里打开 demo 目录即可;tests 目录内容更全面,展示了支持的全部用例。
Size
3 MB
Stars
10.6K
Updated
CommitNov 12
Age
15y
Commits · 90 Days