1

I am making a project in school where we need to make a small website on a specific topic, now I want that when the browser's back button is clicked. I come to my home page which I have included in the code provided above, Please help me!

unnat
  • 11
  • 1

2 Answers2

1

i dont know if it is true or not , but i tried a simple code now , so when user opened our first page , current page URL will save in your session or cookie . after that in second page when user clicked back button you should save that page URL in session again . when user clicked back you have 2 URL and you can check : if these 2 URL matches it means user is in same page , but else user clicked back button . and you must check this in all your pages or in pages you want .

if ($_SESSION['link1'] === $_SESSION['link2']) {
$backClicked = false;
}else {
$backClicked = true;
header("location: Your Home Page");
}
Diyako
  • 651
  • 1
  • 9
  • 24
0

There is no way to control the back button in a browser only using HTML and CSS. You will have to use JavaScript.

With JavaScript you could look to use history.pushState() or history.replaceState() to modify the history of the browser. Adding the homepage to the history, so that when the user clicks the back button that is where they will go.

You can read more about the History API here:

https://developer.mozilla.org/en-US/docs/Web/API/History_API#Interfaces

T. Short
  • 3,481
  • 14
  • 30