Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go Back to Previous Page

Tags:

javascript

php

I am using a form to "Rate" a page. This form "posts" data to a php script elsewhere. I simply want to display a link after the form is processed which will bring the user back to previous page. Can I do this using javascript in my php script?

GF

like image 300
Grunge Freak Avatar asked Mar 30 '10 20:03

Grunge Freak


People also ask

How do I go back in browser?

If you tap and hold the back button in Chrome Android, the option will list out the recently closed history of the website pages that you've visited in the session. This allows you to jump back to any older page without navigating to the subsequent back page.

How do I go back to previous page in Javascript?

The history. back() method loads the previous URL (page) in the history list. The history. back() method only works if a previous page exists.

Can we go back to page one?

Can't we just go back to page one and start all over again?” “The only reason for being a bee is to make honey. And the only reason for making honey is so I can eat it.”


2 Answers

You can use a link to invoke history.go(-1) in Javascript, which is essentially equivalent to clicking the Back button. Ideally, however, it'd be better to just create a link back to the URL from whence the user was posted to the form - that way the proper "flow" of history is preserved and the user doesn't wonder why they have something to click "Forward" to which is actually just submitting the form again.

like image 175
Amber Avatar answered Sep 28 '22 21:09

Amber


Try this:

$previous = "javascript:history.go(-1)"; if(isset($_SERVER['HTTP_REFERER'])) {     $previous = $_SERVER['HTTP_REFERER']; } 

in html:

<a href="<?= $previous ?>">Back</a> 

The JavaScript code is initialize as fallback for HTTP_REFERER variable sometimes not work.

like image 25
rahman Avatar answered Sep 28 '22 23:09

rahman