Skip to main content

Prevent Back button from showing POST confirmation alert



I have an application that supplies long list of parameters to a web page, so I have to use POST instead of GET. The problem is that when page gets displayed and user clicks the Back button, Firefox shows up a warning:







To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier.







Since application is built in such way that going Back is a quite common operation, this is really annoying to end users.





Basically, I would like to do it the way this page does:





http://www.pikanya.net/testcache/





Enter something, submit, and click Back button. No warning, it just goes back.





Googling I found out that this might be a bug in Firefox 3, but I'd like to somehow get this behavior even after they "fix" it.





I guess it could be doable with some HTTP headers, but which exactly?



Source: Tips4all

Comments

  1. One way round it is to redirect the POST to a page which redirects to a GET - see Post/Redirect/Get on wikipedia.

    Say your POST is 4K of form data. Presumably your server does something with that data rather than just displaying it once and throwing it away, such as saving it in a database. Keep doing that, or if it's a huge search form create a temporary copy of it in a database that gets purged after a few days or on a LRU basis when a space limit is used. Now create a representation of the data which can be accessed using GET. If it's temporary, generate an ID for it and use that as the URL; if it's a permanent set of data it probably has an ID or something that can be used for the URL. At the worst case, an algorithm like tiny url uses can collapse a big URL to a much smaller one. Redirect the POST to GET the representation of the data.



    As a historical note, this technique was established practice in 1995.

    ReplyDelete
  2. See my golden rule of web programming here:

    http://stackoverflow.com/questions/638494/stop-data-inserting-into-a-database-twice/638506#638506

    It says: “Never ever respond with a body to a POST-request. Always do the work, and then respond with a Location: header to redirect to the updated page so that browser requests it with GET”

    If browser ever asks user about re-POST, your web app is broken. User should not ever see this question.

    ReplyDelete
  3. One way to avoid that warning/behavior is to do the POST via AJAX, then send the user to another page (or not) separately.

    ReplyDelete
  4. I have an application that supplies long list of parameters to a web page, so I have to use POST instead of GET. The problem is that when page gets displayed and user clicks the Back button, Firefox shows up a warning:


    Your reasoning is wrong. If the request is without side effects, it should be GET. If it has side effects, it should be POST. The choice should not be based on the number of parameters you need to pass.

    ReplyDelete
  5. to provide this msg "To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier." remove this from your htm form "enctype="multipart/form-data" ";)

    ReplyDelete
  6. THIS MAY HELP:

    GO to Tools->Options->Advanced->Network

    UNCHECK "Tell me when a Website asks to store ...

    OR

    ADD the Website that has the problem as an EXCEPTION

    ReplyDelete

Post a Comment

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex