window.history.back()在Chrome中无法正常工作,在Mozilla中可以正常工作 [英] window.history.back() not working right in Chrome, works in Mozilla
问题描述
我有2个按钮提交,用于发布数据并从服务器获取验证错误,还有一个 Cancel 调用window.history.back()
.
I have 2 buttons Submit, which posts the data and gets back validation errors from the server, and a Cancel which calls window.history.back()
.
我点击提交 X次(由于服务器验证错误,帖子在页面上停留了/停留在页面上)
I click Submit X number of times (post comes/stays on the page because of validation errors from server)
在 Chrome 上,我需要单击取消 X次,以返回上一页.
On Chrome I need to click Cancel X times to go back to the previous page.
在 Mozilla 上,我只需单击一次取消.
On Mozilla I only need to click Cancel once.
我想Chrome浏览器会在历史记录中计入POST请求/直接回退,但Mozilla不会.我不熟悉它的工作方式或jquery.有什么我可以解决的吗?
I guess Chrome counts the POST requests/direct backs in the history but Mozilla does not. I am not familiar with how that works or jquery. Is there something I can do to fix this?
编辑:按照建议对链接中的网址进行硬编码.稍后再回来尝试,如果没有人击败我,可以通过将引荐页网址发送到编辑表单以加载到取消按钮中来查看是否可以做到这一点.
EDIT: Going to hard code the urls in the link as suggested. Will come back later to try and see if I can do this by sending the referring page url to the edit form to load into the Cancel button, if no one beats me to it.
…
{{ Form::submit('Create', array('class'=>'btn btn-info')) }}
<a href="{{ URL::previous() }}" class="back btn btn-danger">Cancel</a>
{{ Form::close() }}
<script type="text/javascript">
$(document).ready(function() {
$('a.back').click(function(e) {
e.preventDefault();
window.history.back();
return false;
});
});
…
</script>
推荐答案
万一您需要再次使用,安全的跨浏览器选项是使用history.go(-1);
In case you ever need to use back again, the safe cross-browser option was to use history.go(-1);
这篇关于window.history.back()在Chrome中无法正常工作,在Mozilla中可以正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!