Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old April 3rd, 2006, 06:15 AM
Vivek
Guest
 
Posts: n/a
Default Any way to identify/capture back button event?

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

  #2  
Old April 3rd, 2006, 05:15 PM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
Default 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
  #3  
Old April 5th, 2006, 10:16 AM
Vivek
Guest
 
Posts: n/a
Default 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

  #4  
Old April 5th, 2006, 04:35 PM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
Default 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
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles