Back button with JavaScript/jQuery

This always worked for me to go back.

<a href="javascript:history.back()">BACK</a> 

history is a property from window object and not from an html element. So, this should work:

window.history.back();

instead of:

parent.history.back();

At the end you should have something like this:

$('button#cancel').on('click', function(e){
    e.preventDefault();
    window.history.back();
});

This is going to also prevent the default behavior of your submit button


Your cancel button is still a submit button, so it's going back then submitting the form, sending you forwards again and essentially undoing your back maneuver.

Use

return false;

after the parent.history.back();

to stop the submission from continuing


whith onclick

 <a onclick="window.history.back();" class="btn btn-sm btn-info">back</a>