[英]A button to change 'javascript:history.go() ' history
Usually we use <a href="javascript:history.go(-1)">Back</a>
to go back page.通常我们使用
<a href="javascript:history.go(-1)">Back</a>
返回页面。
I would like to build a button to increase -1
value.我想建立一个按钮来增加
-1
值。
For example, when I click a button history.go(-2)
click again history.go(-3)
like this.例如,当我单击一个按钮
history.go(-2)
再次单击history.go(-3)
像这样。
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
.显然,用
history.go
替换console.log
。
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.
您可以将cookie用于 IE7 覆盖,但localStorage更干净。
<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)
}
})();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.