You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by "CONNER, BRENDAN (SBCSI)" <bc...@sbc.com> on 2005/09/28 01:30:44 UTC

Restricting the user from using the back-button

This may not be a strictly JSF question, but I was wondering if someone
could give pointers on how to selectively restrict the user's ability to
hit the browser's back button.  In particular, after a major operation
is complete, we don't want the user hitting the back button and trying
to enter fields used in the prior transaction.

I would have thought there was some sort of JavaScript "history" event
that I could capture, but I don't see one in any of the JavaScript
references I have.

- Brendan

Re: Restricting the user from using the back-button

Posted by Martin Marinschek <ma...@gmail.com>.
Yes.

With client-side state saving, you are good to use the back button as
much as you want.

Duplicate submits are not handled out of the box, though!

regards,

Martin

On 9/29/05, Simon Kitching <sk...@obsidium.com> wrote:
> Paul Klaer wrote:
> > You don't need to capture the back button.
> >
> > Just add this js snippet to your javascript on each page:
> > "history.forward();"
>
> Interesting - so if the user has used the app normally (ie not used the
> back button) then history.forward does nothing. But if they have used
> back, then as soon as the previous page loads it jumps *forward* to the
> page they were on when they hit the back button, effectively making
> "back" act like a "refresh" button?
>
> The traditional mechanism for preventing people from using the back
> button is to have a hidden field in every page with a counter value, and
> have a corresonding counter value in the user's session. The counter is
> incremented each time a page is served. If a request comes in and the
> values don't match then the user must have used the back button, so they
> are redirected to a page telling them not to do that. I'm not aware of
> any JSF tag that implements this but I wouldn't be surprised to find one
> exists.
>
> I believe that storing user state in the page rather than in the session
> can help with making an app work even when the back button is used. This
>   can be enabled in web.xml:
>      <context-param>
>          <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
>          <param-value>client</param-value>
>          <description>
>              State saving method: "client" or "server"
>          </description>
>      </context-param>
> I haven't experimented with this myself though.
>
> Regards,
>
> Simon
>


--

http://www.irian.at
Your JSF powerhouse -
JSF Trainings in English and German

Re: Restricting the user from using the back-button

Posted by Paul Klaer <pk...@infeurope.lu>.
On Thu, 29 Sep 2005 00:47:05 +0200, Simon Kitching  
<sk...@obsidium.com> wrote:

> Paul Klaer wrote:
>> You don't need to capture the back button.
>>  Just add this js snippet to your javascript on each page:   
>> "history.forward();"
>
> Interesting - so if the user has used the app normally (ie not used the  
> back button) then history.forward does nothing. But if they have used  
> back, then as soon as the previous page loads it jumps *forward* to the  
> page they were on when they hit the back button, effectively making  
> "back" act like a "refresh" button?

No, a "refresh" submits the form values, if any available, again (The user  
has to confirm normally by a popup window). A forward just moves the  
browser forward without submitting the values again.
So, if you really don't want the user to use the back button it's a  
possibility to use that js.


Re: Restricting the user from using the back-button

Posted by Craig McClanahan <cr...@apache.org>.
On 9/28/05, Simon Kitching <sk...@obsidium.com> wrote:
>
> The traditional mechanism for preventing people from using the back
> button is to have a hidden field in every page with a counter value, and
> have a corresonding counter value in the user's session. The counter is
> incremented each time a page is served. If a request comes in and the
> values don't match then the user must have used the back button, so they
> are redirected to a page telling them not to do that. I'm not aware of
> any JSF tag that implements this but I wouldn't be surprised to find one
> exists.


Look no further :-). Shale's token component can be embedded inside your
form to catch resubmits. Instead of redirecting you, though, it triggers a
validation error that will cause the current page to be redisplayed.

Craig

Re: Restricting the user from using the back-button

Posted by Simon Kitching <sk...@obsidium.com>.
Paul Klaer wrote:
> You don't need to capture the back button.
> 
> Just add this js snippet to your javascript on each page:  
> "history.forward();"

Interesting - so if the user has used the app normally (ie not used the 
back button) then history.forward does nothing. But if they have used 
back, then as soon as the previous page loads it jumps *forward* to the 
page they were on when they hit the back button, effectively making 
"back" act like a "refresh" button?

The traditional mechanism for preventing people from using the back 
button is to have a hidden field in every page with a counter value, and 
have a corresonding counter value in the user's session. The counter is 
incremented each time a page is served. If a request comes in and the 
values don't match then the user must have used the back button, so they 
are redirected to a page telling them not to do that. I'm not aware of 
any JSF tag that implements this but I wouldn't be surprised to find one 
exists.

I believe that storing user state in the page rather than in the session 
can help with making an app work even when the back button is used. This 
  can be enabled in web.xml:
     <context-param>
         <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
         <param-value>client</param-value>
         <description>
             State saving method: "client" or "server"
         </description>
     </context-param>
I haven't experimented with this myself though.

Regards,

Simon

Re: Restricting the user from using the back-button

Posted by Paul Klaer <pk...@infeurope.lu>.
You don't need to capture the back button.

Just add this js snippet to your javascript on each page:  
"history.forward();"


On Wed, 28 Sep 2005 01:30:44 +0200, CONNER, BRENDAN (SBCSI)  
<bc...@sbc.com> wrote:

> This may not be a strictly JSF question, but I was wondering if someone
> could give pointers on how to selectively restrict the user's ability to
> hit the browser's back button.  In particular, after a major operation
> is complete, we don't want the user hitting the back button and trying
> to enter fields used in the prior transaction.
>
> I would have thought there was some sort of JavaScript "history" event
> that I could capture, but I don't see one in any of the JavaScript
> references I have.
>
> - Brendan