Jquery history.go(-1); does not work Chrome

Asked

Viewed 521 times

1

I’ve done some research even here on stackoverflow about creating a back button. The situation is that I click on a dynamic record to edit, then I have the option to Cancel (which is to go back) in Ieca and FF works, but in Chrome we have problem.

I’ve tried other alternatives, but nothing worked.

<button type="submit" name="voltar" value="voltar" id="voltar" class="btn btn-default" style="margin-left: 30px">Cancelar</button>


    $('#voltar').click(function() {

        history.go(-1);
        return false;
    });

I have tried something direct inline also in JS, but did not give! Some solution ?

SOLUTION: Apparently what I did to make it work was just take the jquery that was at the bottom of the page and play at the beginning of it. You will understand.

  • This button is generated dynamically by javascript/jquery?

  • This works on Chrome, I believe what should be wrong is how you go to the edit screen. If it is via ajax, remember that it is you who should manipulate browser history.

  • Where is the js posted? In a separate script? On the page itself?

  • Kadu is not.. is a normal html.

  • Guilherme the js/jquery code is on the same page is all very simple!

  • There is no ajax no, I just take record (by id) and take the other page and edit the data.

Show 1 more comment

1 answer

2

I did a test with your code as follows from Chrome and it worked normally:

<button type="submit" name="voltar" value="voltar" id="voltar" class="btn btn-default" style="margin-left: 30px">Cancelar</button>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
    $('#voltar').click(function() {

        history.go(-1);
    return false;
});
</script>
<a href="teste.html?a">link</a>

Anyway try to remove the false Return, in case it is interrupting some action from your page.

OBS: Stay tuned if there really is a page in history to go back to, because the -1 only goes back to the previous position, and if it goes to the same, in some cases it ignores, I suggest you put a link to the page in this case (as in Breadcrumbs).

Abs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.