Hai,
I need to refresh a page "ONLY ONCE" if a visitor visit. I want to do this because if a visitor hit back button in their browser then i need to display fresh content not from the browser cache..
Please help
Thanks
Rajeesh
Hai,
I need to refresh a page "ONLY ONCE" if a visitor visit. I want to do this because if a visitor hit back button in their browser then i need to display fresh content not from the browser cache..
Please help
Thanks
Rajeesh
After you googled your problem, you will probably find the solution in the top 5 displayed.
The numer one page gives a great solution:
<!-- Codes by Quackit.com -->
<a href="javascript:location.reload(true)">Refresh this page</a>
You can apply that code onload, but the problem is that it becomes stuck in a loop. You could use PHP for that:
At the top of the page you place the following:
<?php
session_start(); // This should be at the top of the page
?>
And either in the head or body section:
<?php
if (!isset($_SESSION['alreadyreloaded'])) {
$_SESSION['alreadyreloaded'] = false;
}
// ....................................
// The rest of the page....
// ....................................
if ($_SESSION['alreadyreloaded'] == true) {
$_SESSION['alreadyreloaded'] = false;
} else {
$_SESSION['alreadyreloaded'] = true;
?>
<script type="text/javascript">
window.onload=function(){
setTimeout(function(){
location.reload(true);
},10);
}
</script>
<?php
}
?>
Although it looks a bit strange, it is very difficult to check wether the page has already been refreshed. You can try cookies if your server doesn't support PHP.
~G
Hai
It works in IE and in Mozilla and not working in Opera, Safari. Please help....
Is there is any way to delete the page cache in browser ?
Thanks
Rajeesh
After you googled your problem, you will probably find the solution in the top 5 displayed.
The numer one page gives a great solution:
<!-- Codes by Quackit.com --> <a href="javascript:location.reload(true)">Refresh this page</a>
You can apply that code onload, but the problem is that it becomes stuck in a loop. You could use PHP for that:
At the top of the page you place the following:
<?php session_start(); // This should be at the top of the page ?>
And either in the head or body section:
<?php if (!isset($_SESSION['alreadyreloaded'])) { $_SESSION['alreadyreloaded'] = false; } // .................................... // The rest of the page.... // .................................... if ($_SESSION['alreadyreloaded'] == true) { $_SESSION['alreadyreloaded'] = false; } else { $_SESSION['alreadyreloaded'] = true; ?> <script type="text/javascript"> window.onload=function(){ setTimeout(function(){ location.reload(true); },10); } </script> <?php } ?>
Although it looks a bit strange, it is very difficult to check wether the page has already been refreshed. You can try cookies if your server doesn't support PHP.
~G
Using PHP yes:
The following code demands that the latest version is used. This should be placed at the top of the page:
<?php
$nowGmDate = gmdate('r');
header("Last-Modified: ".$nowGmDate); // Right now
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Pragma: no-cache");
header("Cache-Control: no-cache");
?>
This will make sure that the page is not cached. However, when the page is really extermely frequently visited, it may be cached for like 2 minuts.
Using JS: I don't know.
~G
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.