Return to the previous page by setting a variable

Asked

Viewed 561 times

3

Here’s what I’d like to do

  echo "<script>window.history.back()</script>";

this returns to the previous page

what I intended was to return to the previous page but defining a variable

we imagine that the previous page is example.php

i would like you to do "example.php? a=1"

1 answer

3


To get the previous url:

document.referrer

To redirect to the previous url with additional parameters:

window.location.href = document.referrer+ '?a=1';
  • with window.history.back() the browser kept the fields of the forms previously filled out not to do the same with this :(

  • No, so you will make a new request :/ ... Anyway you can save in, for example: $_SESSION['campos_form']['username'], $_SESSION['campos_form']['email'] etc... And so does not lose the data

Browser other questions tagged

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