javascript - window.history.back() not working right in Chrome, works in Mozilla - Stack Overflow

I have 2 buttons Submit, which posts the data and gets back validation errors from the server, and a Ca

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().

I click Submit X number of times (post es/stays on the page because of validation errors from server)

On Chrome I need to click Cancel X times to go back to the previous page.

On Mozilla I only need to click Cancel once.

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 e 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>

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().

I click Submit X number of times (post es/stays on the page because of validation errors from server)

On Chrome I need to click Cancel X times to go back to the previous page.

On Mozilla I only need to click Cancel once.

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 e 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>
Share Improve this question edited Dec 31, 2014 at 15:19 Howard Renollet 4,7392 gold badges25 silver badges31 bronze badges asked Dec 30, 2014 at 20:53 PhilPhil 2,24611 gold badges36 silver badges58 bronze badges 3
  • If you don't care about preserving the data why don't you just redirect wherever you want the user to go upon canceling? – Hanlet Escaño Commented Dec 30, 2014 at 21:28
  • At the start of the day, I was convinced that I would need to call the edit form from different places... but now I think I don't so! Thanks! – Phil Commented Dec 30, 2014 at 21:35
  • I've never used it myself, but you may be able to use return Redirect::back() to return the user to where ever it was that they came from. – user1669496 Commented Dec 30, 2014 at 21:55
Add a ment  | 

1 Answer 1

Reset to default 5

In case you ever need to use back again, the safe cross-browser option was to use history.go(-1);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744800158a4594442.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信