I have a strange problem that only occurs in some browsers which I cannot find a solution to anywhere.
Here's the objective:
Make a simple page with a hyperlink. When the hyperlink is clicked, a box immediately appears telling the user to wait while the next page is being fetched from the network. If the visitor doesn't have javascript, then the box won't appear and the next page would attempt to load. The non-javascript version is fine, but the javascript version gives problems.
In Firefox version 123.0 and on Chrome 122 for Windows 10, I have the problem where if a user attempts to load the next page then clicks the back button on their browser, the box appears automatically (which should not happen).
In Seamonkey 2.53.18.2 everything works correctly.
Here is the PHP code I used that can reproduce the problem. Heck, the problem may also be reproduced without using the PHP portion.
<?php
//this code fragment simulates when the resource was last updated
//so then I load the resource once and generate status 304 when user clicks the back button
date_default_timezone_set('America/Toronto');
$uset=strtotime("2024-04-13 6:20PM");
$lmod=gmdate("D, d M Y H:i:s T",$uset);
$ifms=$_SERVER["HTTP_IF_MODIFIED_SINCE"];
header('Last-Modified: '.$lmod,true);
if (isset($ifms{1}) && $ifms===$lmod){
header('HTTP/1.1 304 NM',true);exit();
}
?>
<!DOCTYPE HTML>
<html>
<head>
<style>
#wbox{
display:none;
border-radius:1em;
border:1px solid black;
background:#FFFFAA;
color:#000000
}
</style>
</head>
<body>
<h1>Content loader</h1>
<a ID="clickee" href="something.htm">Click here</a>
<div ID="wbox">
<h2>Loading contents...</h2>
</div>
<script>
function showbox(){
document.getElementById('wbox').style.display="block";
}
document.getElementById('clickee').addEventListener("click",showbox);
</script>
</body>
</html>
Could it be that the new browsers are experiencing bugs or is there something I can do to my code to prevent the "loading contents" box from automatically appearing when the user returns to the page by clicking the "back" button.
Oh, and if the user clicks the refresh/reload button after clicking the back button, the problem goes away but its an inconvenience to click 2 buttons when only 1 should be clicked.
As mentioned above, I tested my code in multiple browsers. the "loading contents" box should only appear when leaving the page, not when re-entering the page by use of the browser's "back" button.