Any way to identify/capture back button event?

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
 
T

Thomas 'PointedEars' Lahn

Vivek said:
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);
%>

No, it cannot. Read RFC1945 and RFC2616 (again).
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..

Use the proprietary approach posted a few days ago if you must.
Use server-side sessions otherwise.


PointedEars
 
V

Vivek

Hi Thomas,

Thanks for ur reply..

Thomas :Use the proprietary approach posted a few days ago if you must.
Use server-side sessions otherwise.

Can u please give me the link for the proprietary approach that you are
talking about? I am not able to find the post(actually what query
should i use to find it?)

Thanks,
Vivek Jani
 
T

Thomas 'PointedEars' Lahn

Vivek said:
Thanks for ur reply..
^^
Thanks in advance for not posting like a complete idiot.

<URL:http://jibbering.com/faq/faq_notes/pots1.html>
<URL:http://www.safalra.com/special/googlegroupsreply/>

[repaired quotation]
Can u please give me the link for the proprietary approach that you are ^
talking about? I am not able to find the post(actually what query
should i use to find it?)

Try "onunload" and "Firefox", I do not remember exactly either.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top