Skip to content

Polyfill `history.state` on iOS 5- and Android 4.3-.

Notifications You must be signed in to change notification settings

zpbx/history.state

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

history.state

Polyfill history.state on iOS 5- and Android 4.3-.

简介

iOS 5+ 和 Android 4+ 已经比较稳定地实现了 HTML5 History API(history.pushState()history.replaceState() 方法和 popstate 事件),但直到 iOS 6+ 和 Android 4.4+ 才支持 history.state 属性。

这个属性还是很重要的,通过它,脚本在任何时候都可以获知当前处于哪个 state,而不是只能在 popstate 事件的回调中通过 event.state 来获知。

本项目将在那些支持 popstate 事件但不支持 history.state 属性的浏览器中模拟原生的 history.state 行为。

兼容性

作为一个 polyfill 脚本,本项目是透明的:

  • 在不需要打补丁的环境中,直接退出
  • 在需要打补丁的环境中,模拟原生行为
  • 在无法打补丁的环境中,向控制台报错后退出

本项目的初衷是面向移动浏览器的,将在以下移动平台的主流浏览器中发挥作用:

  • iOS 5.x
  • Android 4.0 ~ 4.3

(更早的移动浏览器对 HTML5 History API 的实现有缺陷,无法保证效果。)

安装

  1. 通过 Bower 安装:

    $ bower install history.state
  2. 在页面中加载本项目的脚本文件:

    <script src="bower_components/history.state/src/history.state.js"></script>

API 文档

所有文档入口在 Wiki 页面,快去看吧!

谁在用?

以下开源项目采用本项目作为基础组件:

因此,本项目运行在以下网站:


License

MIT License

About

Polyfill `history.state` on iOS 5- and Android 4.3-.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 80.2%
  • HTML 19.8%