ENGLISH
=============================================================================================================
This Javascript library provides an emulation of HTML5 History API for older browsers.
The library operates according to W3C specification, adding no new or incompatible methods. The library can be used exactly as described, for example, in Dive Into HTML5 book (http://diveintohtml5.info/history.html) or in the History API Specification (http://www.w3.org/TR/html5/history.html#the-history-interface).
Example of using the library in the pure JS context:
```html
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="history.js"></script>
<script type="text/javascript">
window.onload = function() {
// function for the reference is processed when you click on the link
function handlerAnchors() {
// keep the link in the browser history
history.pushState( null, null, this.href );
// here can cause data loading, etc.
// do not give a default action
return false;
}
// looking for all the links
var anchors = document.getElementsByTagName( 'a' );
// hang on the event, all references in this document
for( var i = 0; i < anchors.length; i++ ) {
anchors[ i ].onclick = handlerAnchors;
}
// hang on popstate event triggered by pressing back/forward in browser
window.onpopstate = function( e ) {
// we get a normal Location object
/*
* Note, this is the only difference when using this library,
* because the object document.location cannot be overriden,
* so library the returns generated "location" object within
* an object window.history, so get it out of "history.location".
* For browsers supporting "history.pushState" get generated
* object "location" with the usual "document.location".
*/
var returnLocation = history.location || document.location;
// here can cause data loading, etc.
// just post
alert( "We returned to the page with a link: " + returnLocation.href );
}
}
</script>
</head>
<body>
<a href="/mylink.html">My Link</a>
<a href="/otherlink.html">Other Link</a>
</body>
</html>
```
Example of using the library along with JQuery:
```html
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="history.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(function() {
// looking for all the links and hang on the event, all references in this document
$("a").click(function() {
// keep the link in the browser history
history.pushState( null, null, this.href );
// here can cause data loading, etc.
// do not give a default action
return false;
});
// hang on popstate event triggered by pressing back/forward in browser
$( window ).bind( "popstate", function( e ) {
// we get a normal Location object
/*
* Note, this is the only difference when using this library,
* because the object document.location cannot be overriden,
* so library the returns generated "location" object within
* an object window.history, so get it out of "history.location".
* For browsers supporting "history.pushState" get generated
* object "location" with the usual "document.location".
*/
var returnLocation = history.location || document.location;
// here can cause data loading, etc.
// just post
alert( "We returned to the page with a link: " + returnLocation.href );
});
});
</script>
</head>
<body>
<a href="/mylink.html">My Link</a>
<a href="/otherlink.html">Other Link</a>
</body>
</html>
```
Example of using popstate (pure JS):
```javascript
window[ window.addEventListener ? 'addEventListener' : 'attachEvent' ]( 'popstate', function( event ) {
// receiving location from the window.history object
var loc = history.location || document.location;
alert( "return to: " + loc );
}, false);
```
Example of using popstate with JQuery:
```javascript
$( window ).bind( 'popstate', function( event ) {
// receiving location from the window.history object
var loc = history.location || document.location;
alert( "return to: " + loc );
});
```
Advanced library configuration:
history.js?basepath=/pathtosite/ - the base path to the site; defaults to the root "/".
history.js?redirect=true - enable link translation.
history.js?type=/ - substitute the string after the anchor; by default, nothing is substituted.
You can also combine options:
history.js?type=/&redirect=true&basepath=/pathtosite/ - the order of options does not matter.
Or execute special method in JavaScript:
history.redirect( /* type = */ '/', /* basepath = */ '/pathtosite/' );
Demo Site: http://history.spb-piksel.ru/
Follow me on Twitter: https://twitter.com/DimaPakhtinov
-------------------------------------------------------------------------------------------------------------
РУССКИЙ
=============================================================================================================
Библиотека эмулирует HTML5 History API в старых браузерах.
Библиотека которая не добавляет ненужные методы заставляя их изучать, а оперирует по спецификации w3c, по интерфейсу History.
Для примера могу привести короткий код как с ней работать.
По принципу мы работаем с HTML5 History API так как описано например тут http://htmlbook.ru/html5/history или по спецификации http://www.w3.org/TR/html5/history.html#the-history-interface
То-есть коротенький пример:
на чистом JS:
```html
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="history.js"></script>
<script type="text/javascript">
window.onload = function() {
// функция для ссылок обрабатывается при клике на ссылку
function handlerAnchors() {
// заносим ссылку в историю
history.pushState( null, null, this.href );
// тут можете вызвать подгрузку данных и т.п.
// не даем выполнить действие по умолчанию
return false;
}
// ищем все ссылки
var anchors = document.getElementsByTagName( 'a' );
// вешаем события на все ссылки в нашем документе
for( var i = 0; i < anchors.length; i++ ) {
anchors[ i ].onclick = handlerAnchors;
}
// вешаем событие на popstate которое срабатыв�
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
meteor的router库 (341个子文件)
mocha.css 3KB
style.css 3KB
chrome.css 1KB
style.css 1KB
style.css 256B
style.css 200B
style.css 199B
style.css 199B
simple-routed-app.css 45B
app-with-layout.css 31B
simple-auth-app.css 31B
blank.gif 49B
.git 100B
.git 91B
.gitignore 21B
.gitignore 16B
.gitignore 16B
.gitignore 16B
.gitignore 16B
.gitignore 13B
.gitmodules 207B
binaryfile.tar.gz 301B
index.html 3KB
directory.html 2KB
base64.html 2KB
index.html 1KB
index.html 1KB
simple-routed-app.html 1KB
index.html 1008B
app-with-layout.html 588B
index.html 511B
index.html 506B
index.html 480B
index.html 466B
index.html 449B
index.html 389B
index.html 340B
simple-auth-app.html 306B
error.html 276B
favicon.ico 1KB
list.jade 268B
mocha.js 81KB
chai.js 81KB
history.js 43KB
history.iegte8.js 35KB
history.js 33KB
history.iegte8.js 27KB
test-incoming-form.js 20KB
incoming_form.js 12KB
session.js 10KB
index.js 10KB
page.js 10KB
history.min.js 9KB
send.js 9KB
history.min.js 9KB
multipart_parser.js 8KB
utils.js 8KB
index.js 8KB
history.iegte8.min.js 8KB
logger.js 7KB
history.iegte8.min.js 6KB
staticCache.js 6KB
proto.js 6KB
router_client.js 5KB
query.js 5KB
directory.js 5KB
router_client_tests.js 5KB
app.js 5KB
router_common.js 4KB
index.js 4KB
compress.js 3KB
router_server.js 3KB
router_server_tests.js 3KB
cookieSession.js 3KB
multipart.js 3KB
tests.js 3KB
basicAuth.js 3KB
mime.js 2KB
debug.js 2KB
session.js 2KB
test-fixtures.js 2KB
errorHandler.js 2KB
debug.js 2KB
test-multi-video-upload.js 2KB
test-file.js 2KB
memory.js 2KB
cookie.js 2KB
index.js 2KB
static.js 2KB
crc.test.js 2KB
test-multipart-parser.js 2KB
multipart.js 2KB
test-incoming-form.js 2KB
limit.js 2KB
simple-routed-app.js 2KB
json.js 2KB
json.js 2KB
favicon.js 2KB
store.js 2KB
csrf.js 2KB
共 341 条
- 1
- 2
- 3
- 4
资源评论
- HuangQQ2015-08-27文件应该能用,但是我还是没配置成功,伤心啊!
ec_huyinghuan
- 粉丝: 53
- 资源: 30
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功