Connecting Tech Pros Worldwide Forums | Help | Site Map

Any way to identify/capture back button event? (Con'd)

Newbie
 
Join Date: Jun 2007
Posts: 3
#1: Jun 21 '07
Hi,

I have a question which is related to an old question submitted in this forum but was not fully answered.

The original question is at Any way to identify/capture back button event? .

Does anyone can help adjusting the solution to support
(1) firefox (currently it fails - onload/onunload goes into infinite loop since onunload is being called right after location.reload (unlike IE)
(2) avoid the browser popup message alerting about re-submitting HTTP post request

I am sorry if this is a dumb question, I am new to javascript and I tried solving it for few days with no use.

Thanks

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Jun 22 '07

re: Any way to identify/capture back button event? (Con'd)


yosicco, welcome to TSDN!

You need to use onbeforeunload instead. See this link.
Newbie
 
Join Date: Jun 2007
Posts: 3
#3: Jun 24 '07

re: Any way to identify/capture back button event? (Con'd)


Quote:

Originally Posted by acoder

yosicco, welcome to TSDN!

You need to use onbeforeunload instead. See this link.

Thanks a lot ACoder - it works!!! :)

I have one problem left, since I'm using HTTP POST request, when I click the back button a warning message of the browser is being displayed (something like "To display the web page again, Internet Explorer needs to resend the information you've previously submitted...") - In my case the re-post is completely harmless and I would like to eliminate this message - is there a way to eliminate it?

Thanks again,
yossico
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#4: Jun 25 '07

re: Any way to identify/capture back button event? (Con'd)


Quote:

Originally Posted by yossico

Thanks a lot ACoder - it works!!! :)

It's non-standard, but it works in most browsers, I think.

Quote:

Originally Posted by yossico

I have one problem left, since I'm using HTTP POST request, when I click the back button a warning message of the browser is being displayed (something like "To display the web page again, Internet Explorer needs to resend the information you've previously submitted...") - In my case the re-post is completely harmless and I would like to eliminate this message - is there a way to eliminate it?

There is the PRG (Post, Redirect, Get) approach. It's discussed in The only thing to fear of the back button...is fear itself - see the related links too.
Newbie
 
Join Date: Jun 2007
Posts: 3
#5: Jun 25 '07

re: Any way to identify/capture back button event? (Con'd)


Quote:

Originally Posted by acoder

It's non-standard, but it works in most browsers, I think.


There is the PRG (Post, Redirect, Get) approach. It's discussed in The only thing to fear of the back button...is fear itself - see the related links too.

Again, thanks alot acoder for your swift reply.

I am afraid I will not be able to change the architecture of the application to use redirect/HTTP GET (at least not without significant development cost).

Is this the only way to eliminate the warning message of browsers?

Thanks.
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#6: Jun 25 '07

re: Any way to identify/capture back button event? (Con'd)


Quote:

Originally Posted by yossico

Again, thanks alot acoder for your swift reply.

I am afraid I will not be able to change the architecture of the application to use redirect/HTTP GET (at least not without significant development cost).

Is this the only way to eliminate the warning message of browsers?

Thanks.

I'm sorry - not that I'm aware of.
Newbie
 
Join Date: Aug 2009
Posts: 1
#7: Aug 12 '09

re: Any way to identify/capture back button event? (Con'd)


You can do this with javascript. You need to get a little creative but it works. You might be able to work this into your POST.

http://www.dmcinfo.com/Blog/articleT...-Snippets.aspx
Reply