Checkbox / backbutton depending on browser

I have implemented the site in .jsp / JSTL / EL which works great. However, depending on the browser (!), The behavior of the back button varies slightly.

I took care not to have a double message (so that the browser does not warn the user that he will send the message again), but apparently this leads to another problem: if I use the back button from Chrome then the value checkboxes are incorrect.

Here is the scenario as I understand it:

  • user is on page / page1 then checks the checkbox
  • POST is performed, there is an HTTP redirect
  • GET is executed, page / page2 is rendered ok, the checkbox is checked as it should be
  • the user accesses the back button.
  • the user goes back to / page 1 as it was before the checkbox was checked (this is exactly the expected behavior for the back button) , but . This box is still checked.

From looking at the server log and the log of my application, as far as I can see, nothing is being passed to the web server. So it's purely client-side that everything happens.

What's going on and how can I fix it? (without using a framework, this is not the question in question)

EDIT I should probably go into a bit more detail ... The Webapp is already a little "quirky" in that every page, running in a tiny URL style, is state-matched. Everything is "public": anyone can see any page (but it can be private, with private URLs). Anyway: if a user shares any of his page, when another user has to open the page, it should render correctly, and the checkboxes are correctly initialized.

All this suggests that the problem is not on the server side, where the "state" would somehow be wrong: if user A swaps pages ... / 1d2eof then user B opens the page ... / 1d2eof you will see the correct page ...

The only time this gets confused is when the user is using the back button. Remember, at any given moment, I have the full state of the page available on the server side. However, my problem is that apparently nothing communicates with my server when using the back button, so I have no way to "fix the page" for the user who used the back button.

Perhaps double forwarding will help ??


source to share

3 answers

This is a browser feature: clicking the back button restores the final state of the form. If you want to reset the content of a form to what was specified in the HTML (for example, to a state before user interaction), you can use document.formName.reset()

where formName

is the name of the form. (Unfortunately, it's a little tricky to detect when the user pressed the back button and returned to the current page, so it's tricky to determine when to run the above bit of code.)



This is how I solved mine using a hidden field combo and query.

<script type="text/javascript">
    jQuery(document).ready(function () {

    if (!(window.location.toString().indexOf('&FIP') >= 0) && (document.getElementById("<%= hdnField.ClientID %>").value.toString() == "BackButtonClickIsSet")) {

    if (!(window.location.toString().indexOf('&FIP') >= 0)) {
        document.getElementById("<%= hdnField.ClientID %>").value = "BackButtonClickIsSet";

    if (window.location.toString().indexOf('&FIP') >= 0) {
        document.getElementById("<%= hdnField.ClientID %>").value = "BackButtonClickIsNotSet";


<asp:HiddenField ID="hdnField" runat="server" Value="BackButtonHiddenField" />




You might want to take a look at

It offers the ability to take control of what happens on the client side (and possibly the server side with ajax) when the back button is clicked.



All Articles