Connecting Tech Pros Worldwide Help | Site Map

Any way to identify/capture back button event?

Vivek
Guest
 
Posts: n/a
#1: Apr 3 '06
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[i].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

Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#2: Apr 3 '06

re: Any way to identify/capture back button event?


Vivek wrote:
[color=blue]
> 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);
> %>[/color]

No, it cannot. Read RFC1945 and RFC2616 (again).
[color=blue]
> 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..[/color]

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


PointedEars
Vivek
Guest
 
Posts: n/a
#3: Apr 5 '06

re: Any way to identify/capture back button event?


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

Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#4: Apr 5 '06

re: Any way to identify/capture back button event?


Vivek wrote:
[color=blue]
> Thanks for ur reply..[/color]
^^
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][color=blue][color=green]
> > Use the proprietary approach posted a few days ago if you must.
> > Use server-side sessions otherwise.[/color]
>
> Can u please give me the link for the proprietary approach that you are[/color]
^[color=blue]
> talking about? I am not able to find the post(actually what query
> should i use to find it?)[/color]

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


PointedEars
Closed Thread


Similar JavaScript / Ajax / DHTML bytes