Skip to content

lee1994522/vhistory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vhistory.js

Vhistory.js extends HTML5 History's API with a manually maintained stack of the history.It allows you to read and operate the history stack directly.

Usage

<script type="text/javascript" src="/vhistory/vhistory.js"></script>

API

history.getStack()

history.getStacks returns the current stack of your history

var stack = history.getStack();

console.log(stack)
//['/APage','/BPage','CPage']
});

history.backTo(target:string,nearEnd:boolean)

history.backTo receives two arguments,the first arg is the target path you want to go back,the second arg decides whether the target is at the near-end or the far-end(if you have entered the target page twice or more),default is true.

history.backTo('/APage')

history.forwardTo(target:string,nearEnd:boolean)

The same usage but the opposite direction as history.backTo

history.getDistance(target:path,nearEnd:boolean)

history.getDistance will return the distance between the target path and your current path. The default value of nearEnd is true

//if your history stack is ['/APage','/BPage','/APage','/CPage','/DPage']
//and the current path is CPage

console.log(history.getDistance('/APage'));  //-1

console.log(history.getDistance('/APage',false))  //-3

console.log(history.getDistance('/DPage') //1

About

enhance HTML5 History API

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published