V
Vivek
Hi all,
I have a problem in my web-app wherein I need to get the latest page
from server on clicking of back button..
I know that it can be done by preventing/disabling the cache in jsp as
<%
response.setHeader("Cache-Control","no-cache") ;// HTTP 1.1
response.setHeader("Pragma","no-cache");// HTTP 1.0
response.setDateHeader("Expires", -1);
%>
But that shows the ugly browser message asking if I want to repost the
information since most of the pages are POST..
To avoid this I came across the following script in jsp and javascript
that uses cookies and tries to reload the page from server if it is
found from cache..
<%Cookie mycookie = new Cookie("FromValue","Server");
response.addCookie(mycookie);
%>
<html>
<head>
</head>
<body>
<H3>This is a test for documents being pulled from the cache</H3>
<p></p>
<a href="http://www.google.com"> Click here to go to a different page,
then use the Back button to come back to this page.</a>
<script language=javascript>
function winload()
{
//alert("Load "+document.cookie);
var aCookie = document.cookie.split(";");
var value;
for (var i=0; i < aCookie.length; i++)
{
// a name/value pair (a crumb) is separated by an equals sign
var aCrumb = aCookie.split("=");
alert(aCrumb[0]+"="+aCrumb[1]);
if (aCrumb[0] == "FromValue") {
value = unescape(aCrumb[1]);
break;
}
}
//alert(value);
if ((value != null) && (value == "Cache"))
{
alert("Reloading from server ... ");
location.reload(true);
//location.href=location.href;//
}
}
function winunload()
{
var val = "Cache";
document.cookie = "FromValue=" + escape(val) + ";";
}
window.onload = winload;
window.onunload = winunload;
</script>
</body>
</html>
This page works fine in Internet Explorer but gives a problem in
Firefox...it actually goes in a sort of infinite loop in the
load/onload events..and have not been able to correct it..Is there any
other way a back button event can be detected?
Please reply asap,
Thanks,
Vivek Jani
I have a problem in my web-app wherein I need to get the latest page
from server on clicking of back button..
I know that it can be done by preventing/disabling the cache in jsp as
<%
response.setHeader("Cache-Control","no-cache") ;// HTTP 1.1
response.setHeader("Pragma","no-cache");// HTTP 1.0
response.setDateHeader("Expires", -1);
%>
But that shows the ugly browser message asking if I want to repost the
information since most of the pages are POST..
To avoid this I came across the following script in jsp and javascript
that uses cookies and tries to reload the page from server if it is
found from cache..
<%Cookie mycookie = new Cookie("FromValue","Server");
response.addCookie(mycookie);
%>
<html>
<head>
</head>
<body>
<H3>This is a test for documents being pulled from the cache</H3>
<p></p>
<a href="http://www.google.com"> Click here to go to a different page,
then use the Back button to come back to this page.</a>
<script language=javascript>
function winload()
{
//alert("Load "+document.cookie);
var aCookie = document.cookie.split(";");
var value;
for (var i=0; i < aCookie.length; i++)
{
// a name/value pair (a crumb) is separated by an equals sign
var aCrumb = aCookie.split("=");
alert(aCrumb[0]+"="+aCrumb[1]);
if (aCrumb[0] == "FromValue") {
value = unescape(aCrumb[1]);
break;
}
}
//alert(value);
if ((value != null) && (value == "Cache"))
{
alert("Reloading from server ... ");
location.reload(true);
//location.href=location.href;//
}
}
function winunload()
{
var val = "Cache";
document.cookie = "FromValue=" + escape(val) + ";";
}
window.onload = winload;
window.onunload = winunload;
</script>
</body>
</html>
This page works fine in Internet Explorer but gives a problem in
Firefox...it actually goes in a sort of infinite loop in the
load/onload events..and have not been able to correct it..Is there any
other way a back button event can be detected?
Please reply asap,
Thanks,
Vivek Jani