Sunday, November 29, 2009

How do I prevent broswers back button from going back to previous page (IE/Firefox)?

How do I prevent broswers back button from going back to previous page (IE/Firefox)?



I have an interactive form that accepts user inputs and when you press the next button in it, it loads the value in to the database and if you click back button(the application's) the page displays all the submitted values, you can either edit or delete line by line. enough of the application description.



my problem is if I click the browsers back button once or twice, the form is getting resubmitted and adds duplicate of the same information that I entered, also it gets submitted to the databasse. How do I prevent the browsers backbutton from going back.? I need to stop the browser and prevent the form from resubmitting.



Alert window will not prevent form from resubmitting i guess.



opening in a new window is a temporary solution.



Please let me know if you have any other ideas?



How do I prevent broswers back button from going back to previous page (IE/Firefox)?windows mobile





You can't prevent the user from going back, what you need to do is prevent going back from resubmitting the form data.



You do this using the Post-Redirect-Get pattern.



1. User submits form



2. Form handler adds data to database



3. Form handler issues a 302 Redirect



4. A different handler displays a page to the user



The form handler itself does NOT return a normal webpage to the user.



When the user clicks back, they go from the the display handler to the form and skip the form data submission process entirely.



How do I prevent broswers back button from going back to previous page (IE/Firefox)?www.microsoft.com internet explorer



You can try cleaning you history and cookies, then there is nowhere to go back to. set it to automatic o days history and auto clean so it would not pile up
There is three ways you could siable the back history button in the browser.



First you could use the New window option you mentioned in your question but use the toolbar = "no" option so there is no back button at all.



Second, you could add the code:



SCRIPT LANGUAGE="JavaScript"%26gt;



function goNewWin() {



// Make sure if you do this to put the next six lines as one long line



window.open



("backbuttonnewpage.html",



'TheNewpop','toolbar=1,



location=1,directories=1,



status=1,menubar=1,



scrollbars=1,resizable=1');



self.close()



}



%26lt;/SCRIPT%26gt;



%26lt;A HREF="javascript:goNewWin()"%26gt;Click to go to a new page%26lt;/A%26gt;



Third, you could use the classic frames trapper"



%26lt;FRAMESET COLS="100%,*"%26gt;



%26lt;FRAME SRC="goback.html"%26gt;



%26lt;FRAME SRC="fillerpage.html"%26gt;



%26lt;/FRAMESET%26gt;



%26lt;META HTTP-EQUIV="refresh" CONTENT=".0; URL=nobackpage.html"%26gt;



The problem with these three solutions though is that simply by right clicking and selecting back the user gets around the supposed fix.



However there is a far simpler fix which I think you may have over looked.



Simply add this code to your onSubmit handler on your form:



document.yourFormName.reset();



This will clear the fields as the data is sent, so when they return the fields will be empty.

No comments:

Post a Comment

 
web hosting talk