Link to home
Create AccountLog in
Avatar of Colin Brazier
Colin BrazierFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Avoid confirm on browser back button

Hi experts,

If I choose one option from a menu, and then hit the browser back button, I am asked to confirm resubmission...is there any way I can avoid having to do this and go straight back to the menu?

I am looking at this from the developer's viewpoint, I don't want my users being asked to confirm after simply hitting the back button.

Or is it by design?

Cheers,
   
    Col
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

It depends on the design of the application.  Key question: Is there any effect from resubmitting the previous page repeatedly?  If the operation on the previous page (the page you're going back to) is nullipotent, there is no reason to trigger the confirmation.  You can avoid the confirmation by using the GET method to make the request on the previous page.  And in some cases, if the operation on the previous page was idempotent, you can mess around with the JavaScript to change the URL of the previous page.

A good understanding of the HTTP protocol will help you see what is happening.
https://www.experts-exchange.com/articles/11271/Understanding-Client-Server-Protocols-and-Web-Applications.html

Here is the usual sequence of events that triggers the confirmation request:

Request #1: Client visits a web page that contains an HTML form with POST-method
Request #2: Client submits the POST-method request
Response: Server does something with the POST request and produces a "thank you" page
Request #3: Client sees the "thank you" and hits the back button, causing the POST request to be submitted again

This used to be a problem in about 1999 when clients would accidentally pay for things twice or three times by hitting the back button to see if slow, balky servers were actually getting their orders.  Today we use cookies, databases, and other tools to prevent duplicate submissions, so it's less of a problem.
Avatar of Manju
my guess is you have put your menu fields in a form. If yes, then its working as designed. However we dont usually use menu in a form.


There are many online menu creators available which you can plugin with your webpage. My personal selection is www.milonic.com 

This way you can get out of the confirmation window and it also would give an elegant look n feel.
Avatar of Colin Brazier

ASKER

Thanks both.

I only use plugins if they're absolutely necessary, but I'll take a look at it anyway.

Is there any effect from resubmitting the previous page repeatedly?
No.

Here's the menu code
<!-- CONTENT START --->
<div id="head_title" class="blue_3">Administration Menu</div>
<img id="head_img" src="../images/smallspheresh.jpg">
<div id="table_box2">
    <div>
        <p class="con_medium_normal">Welcome to the Website Administration Section</p>
        <table id="admin_menu_table">
            <tr>
            	<td colspan=3>&nbsp;</td>
            </tr>
            <tr>
            	<td><a href="?wh=teachers" class="button large brown" >Teachers</a></td>
            	<td><a href="?wh=stop_press" class="button large brown" >Stop Press</a></td>
            	<td>&nbsp;</td>
            </tr>
            <tr>
            	<td colspan=3></td>
            </tr>
            <tr>
            	<td><a href="?wh=newsletters" class="button large brown" >Newsletters</a></td>
            	<td><a href="?wh=letters" class="button large brown" >Letters home</a></td>
            	<td>&nbsp;</td>
            </tr>
            <tr>
            	<td><a href="?wh=diary" class="button large brown" >Diary</a></td>
            	<td colspan=2 style='height:20px;'>&nbsp;</td>
            </tr>
            <tr>
            	<td><a href="?wh=clubs" class="button large brown" >Clubs and Activities</a></td>
            	<td><a href="?wh=curriculum" class="button large brown" >Curricula</a></td>
            	<td>&nbsp;</td>
            </tr>
            <tr>
            	<td colspan=3></td>
            </tr>
            <tr>
            	<td colspan=3><?php include (HTML_PATH.DS.'logout.html.php'); ?></td>
            </tr>      
        </table>    
    </div>
</div>

Open in new window


So the navigation is controlled by $_GET.  So by hitting the back button I'd simply want to remove the ?xxx part of the URL.  Could you show me the js code I'd need to do this please, as I guess that would be what's needed here.
I see nothing  in this HTML that would trigger a confirmation.  Installed on my own server, here:
http://iconoun.com/demo/temp_colinspurs.php

Click around that page a bit and see if you get the confirmation message.  I don't.  So the effect may be coming from somewhere else.
I don't either.  I did think it very odd, so it must be coming from somewhere else.  

It doesn't matter what option is selected, here's the code from "view source" for the simplest.  The html is built by including portions of html (header, content, footer) from a php index file.
ee_source.html
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
OK, will do.

Cheers.
Thanks, the delay in getting back to you was because I was re-jigging the code to get rid of all those extra form elements.  Seems to be working as required now.