0

I have 3 domains - A.com, B.com, C.com (we can simulate this using tunnels)

The first domain has the pages index.html and page2.html

Here is the homepage of A.com

<head>
  <title>Domain A page 1</title>
</head>

<body>
  <h1>Domain A page 1</h1>
  <a href="/page2.html">Click here to go to page 2</a>
</body>

page2 will automatically send the buyer to domain B.com

<body>
  <h1>Domain A page 2</h1>
  <a href="https://B.com">Click here to go to domain B</a>
</body>

<script>
  history.pushState({}, "", window.location.href);
  window.location.assign("https://B.com");
</script>

The second domain B.com has a page (index.html) that automatically redirects to the third domain C.com

<head>
  <title>Domain B page 1</title>
  <script>
    function goToC() {
      console.log("Redirecting to the C page using form...")
      document.getElementById("p").submit();
    }
  </script>
</head>

<body>
  <h1>Domain B page 1</h1>
  <form id="p" method="get" action="https://C.com">
  </form>

  <button onclick="goToC()">Click here to go to domain C</button>

  <script>
    goToC();
  </script>
</body>

And finally there is nothing special in C.com

<head>
  <title>Domain C page 1</title>
</head>

<body>
  <h1>Domain C page 1</h1>
  <p>Domain C page 1</p>
</body>

So the user action sequence is

  1. Go to A.com/index
  2. Click on link to go to A.com/page2.html
  3. Get automatically sent to B.com
  4. Get automatically sent to C.com

On pressing the back button at C.com they come back to A.com/index bypassing A.com/page2 and B.com

How do I ensure that on pressing the back button they come back to A.com/page2 and not A.com/index ? I've tried using the history API but doesn't seem to solve the problem.

kchak
  • 7,570
  • 4
  • 20
  • 31
  • 1
    Does this answer your question? https://stackoverflow.com/questions/1462719/javascript-change-the-function-of-the-browsers-back-button – RAllen May 23 '23 at 03:45
  • Not really. I have tried using the history API. I think there are security features (I might be wrong) which prevent history manipulation outside your domain. But in this case it doesn't have anything to do with history. The issue is when your page does an auto redirect to another domain, pressing the back button doesn't bring the user back to the page that does the auto redirect. Instead the user comes right back to the previous page where they had to take a manual action. Why is that? – kchak May 23 '23 at 05:36

0 Answers0