Javascript history.go(-1) 返回在 Chrome 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3206830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
history.go(-1) going back doesnt work in Chrome
提问by Stewie Griffin
href="#" onclick="closeOrCancel()and history.go(-1)in that js method doesnt work in Chrome (neither history.back())
href="#" onclick="closeOrCancel()并且history.go(-1)该 js 方法在 Chrome 中不起作用(都不是history.back())
It works with href="javascript:closeOrCancel()", but Opera doesn't allow href="javascript:...
它适用于href="javascript:closeOrCancel()",但 Opera 不允许href="javascript:...
How to make history go back using onclick= "myFunction()" ?
如何使用 onclick="myFunction()" 返回历史记录?
Edit: closeOrCancel()returns false
编辑:closeOrCancel()返回假
回答by TNi
Adding a return false;to the onclickcode seems to be enough:
return false;在onclick代码中添加 a似乎就足够了:
<a href="#" onclick="closeOrCancel(); return false;">Go Back</a>
回答by Jani Hartikainen
You're wrong about two things here:
这里有两件事你错了:
- Opera allowshref="javascript:...
- history.go(-1) worksin Chrome.
- Opera允许href="javascript:...
- history.go(-1)的作品在Chrome中。
Please provide source for your script, since the problem is clearly in it and not the browsers.
请提供您的脚本的来源,因为问题显然出在它而不是浏览器中。
Just put this in a html file and open it to see for yourself:
只需将它放在一个 html 文件中并打开它自己看看:
<script>
function goback() {
history.go(-1);
}
</script>
<a href="javascript:goback()">goback</a>
<a href="#ttttt">tt</a>
First click the "tt" link, then "goback". See the hash change. It works fine, although I'd personally recommend against using javascript in href's.
首先点击“tt”链接,然后点击“goback”。查看哈希更改。它工作正常,尽管我个人建议不要在 href 中使用 javascript。
回答by Rahul Dhokia
I used history.go(-2);to go back to step 1 in chrome.
我曾经history.go(-2);回到 chrome 的第 1 步。

