Usually we use <a href="javascript:history.go(-1)">Back</a>
to go back page.
I would like to build a button to increase -1
value.
For example, when I click a button history.go(-2)
click again history.go(-3)
like this.
Is it possible?
Here's an example function using closures :
<a id="backer" href="">back</a>
...
document.getElementById('backer').onclick = (function () {
var x = -1;
return function () {
console.log(x--)
}
})();
Obviously, replace console.log
with history.go
.
I just thought about the fact that this is using the back button. You could use cookies for IE7 coverage, but localStorage is so much cleaner.
<a id="backer" href="">back</a>
...
document.getElementById('backer').onclick = (function () {
var x = window.localStorage['background'] | 0;
return function () {
x = x - 1;
window.localStorage['background'] = x;
history.back(--x)
}
})();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.