简体   繁体   English

history.go(-1)不适用于chrome。 还有其他选择

[英]history.go(-1) does not work on chrome. Any alternative?

In my project I am using below Javascript code history.back(); 在我的项目中,我使用的是Javascript代码history.back(); for gooing back to previous page.(like back arrow on window). 回到上一页。(如窗口上的后退箭头)。 This function is working fine on IE and Firefox but not on google crome? 这个功能在IE和Firefox上工作正常但在谷歌crome上没有?

<input type="button" value="Go back" onclick="history.go(-1); return false" />

I get the error bellow 我明白了这个错误

Confirm Form Resubmission 确认重新提交表单

This web page requires data that you entered earlier in order to be properly displayed. 此网页需要您之前输入的数据才能正确显示。 You can send this data again, but by doing so you will repeat any action this page previously performed. 您可以再次发送此数据,但通过这样做,您将重复此页面之前执行的任何操作。 Press Reload to resend that data and display this page. 按“重新加载”重新发送该数据并显示此页面。

Did googling but everybody is suggesting history.go(-1);return false; 谷歌搜索,但每个人都在建议history.go(-1);返回false; but it does not work either. 但它也不起作用。 Also tried history.back() but that does not help too 还尝试过history.back(),但这也无济于事

The previous page was displayed after a POST request (usually occurs when submitting a form). POST请求后显示上一页(通常在提交表单时发生)。 That means, to display the previous page, the form data, which was submitted in the POST request, must be submitted again. 这意味着,要显示上一页,必须再次提交在POST请求中提交的表单数据。 It has nothing to do with your history.go(-1) of Javascript, it will also occur when you press the back button of your browser. 它与您的history.go(-1)的Javascript无关,当您按下浏览器的后退按钮时也会发生这种情况。

You can use the Post Redirect Get pattern do work around this problem. 您可以使用Post Redirect Get模式解决此问题。

You can also use GET on your form instead: 您也可以在表单上使用GET:

<form action="..." method="GET">

However, do not use this for forms where data is added on your server, or it will be submitted everytime the user the back button and comes back to this page. 但是,不要将此用于在服务器上添加数据的表单,或者每次用户使用后退按钮并返回此页面时都会将其提交。 See also: When should I use GET or POST method? 另请参阅: 我应该何时使用GET或POST方法?

Try this: 尝试这个:

<script>
function goback() {
    history.go(-1);
}
</script>
<a href=”javascript:goback()”>Back</a>

It works in Chrome and other browsers. 它适用于Chrome和其他浏览器。

The above was copied verbatim from: 上面的内容是逐字复制的:

http://simonthegeek.com/technical/history-back-problems-with-chrome-and-safari/ http://simonthegeek.com/technical/history-back-problems-with-chrome-and-safari/

I would prefer client side code instead of harrasing my server 我更喜欢客户端代码而不是骚扰我的服务器
I tried this and it worked on all browsers: 我尝试了这个,它适用于所有浏览器:

<button onclick="javascript:window.history.back()">Back</button>  

EDIT 编辑
Alternately you can use web cache to store which was your last page and then you can easily redirect on that page.. 或者,您可以使用Web缓存来存储哪个是您的最后一页,然后您可以轻松地在该页面上重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM