Make browser to go back by reloading page 1st and then scrolling it back again too
Posted
by Marco Demaio
on Stack Overflow
See other posts from Stack Overflow
or by Marco Demaio
Published on 2010-05-31T19:28:52Z
Indexed on
2010/05/31
19:33 UTC
Read the original article
Hit count: 379
EXPLAINING WHAT I'M TRYING TO SOLVE:
I have a webpage (file_list.php
) showing a list of files, and next to each file there is a button to delete it. When user press the DELETE button close to a certain file name, the browser goes to a script called delete_file.php
that deletes the file and then it tells browser to go back to the file_list.php
delete_file.php
uses a simple header("Location: file_list.php”);
to go back to file_list.php
When browser goes back to file_list.php
it reloads the page, but it DOES NOT scroll it back again to where the user was before. So let's say the user scrolled the files list and deleted the last file, when the browser shows again the page file_list.php
it won't be scrolled to the bottom of the page again.
THE WORKAROUND I CAME OUT WITH:
I found a strange way to work around this, basically instead of using header("Location: file_list.php”);
in delete_file.php
I simply use a javascript call window.history.go(-1)
.
This workaround works perfectly when user is in session (simply using PHP session_start
function): the browser RELOADS the file_list.php page and then scrolls it also bask to where it was before.
But if the user is NOT in session the browser scrolls the page but IT DOES NOT RELOAD IT before, so the user would still see the file he deleted in the file list.
THE QUESTIONS
Do you know how to reproduce the behavior of the browser when goes back being in session even if we are not in session?
Do you know a way out of this, even another way of solving this matter?
Thanks!
*I know I could use AJAX to delete the file so I would not have to go every time to delete_file.php, but this is not the answer*.
© Stack Overflow or respective owner