Script to go back to the previous updated page?

Asked

Viewed 55,067 times

3

Well, I wanted something that did that when a person clicked to go to a page they were redirected to the previous page.. But the page updates...

Is that I made a small system of comments, when I click to comment it goes to an "Insertcomment" page but I need it to go back to the original page...

  • It should not be the case to redirect automatically after the form is submitted?

3 answers

13


You can do it in the following ways:

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

or using:

<script>
    document.write('<a href="' + document.referrer + '">Go Back</a>');
</script>

3

If it is automatically, after the form is submitted, metes on the page that form Object will open:

<body onload='window.history.back();'>

2

Other possibilities to return to the previous page:

history.go(-1);

window.open(document.referrer,'_self');

location.href = document.referrer;

Examples for testing:

<button onclick="history.go(-1);">Voltar 1</button>

<button onclick="location.href = document.referrer;">Voltar 2</button>

<button onclick="window.open(document.referrer,'_self');">Voltar 3</button>

Reference:

http://www.guj.com.br/t/como-voltar-para-a-pagina-anterior-jsp/153165/3

Browser other questions tagged

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