How to manage a browser button
Why would you want to do that?
You can prevent them from leaving the page using Javascript, but if you can't use that, then there's nothing to be done.
Typically you should use the unload event in the body (for example in jQuery, just add
jQuery(window).unload(function(evt){
if(!confirm('Do you really want to leave')){
evt.preventDefault();
}});
The prototype has something like this, and for pure Javascript, I think it still depends on the browser you are using, but window.unload = function(evt){return false;}
might work.
Can't remember the correct syntax for it.
but I don't know if you can restrict this to only the back or if it will run for all uploads (like clicking on a link, closing the browser, etc.).
If you want to stop them because they might have unsaved data in the form, then that's okay. If you want them not to return for another reason, I think you should rethink why.
a source to share
Typically, if using the back button can cause problems, you already have big problems.
What you probably want to do is check that you are doing things like this:
- Use POST for all requests that change data
- Use nonces (unique identifiers) to prevent forms from being submitted twice
a source to share