Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Browser Back Button

Status
Not open for further replies.

MSch

Programmer
Dec 12, 2001
3
US
Here's my problem: The company I am working for wants the customer returned to the site's home page when the back-button is hit. I put another (form)back-button on the page, but that does not alleviate security issues. My client does not want the customer to see the registration pages again (to prevent re-submits). If you have any suggestions I would sure appreciate it. I've been beating my head against the wall on this.

MikeS
 
I can think of a couple of things to do.

To prevent the user from submitting the form more than once, you can cause the submit button to load the next page so that it overwrites the URL in the browser's history. You do this with JavaScript replace() function:
Code:
<input type=&quot;submit&quot; value=&quot;Submit&quot; onClick=&quot;replace(url_goes_here);&quot;>
Look at a JavaScript book for more details. You will have to experiment to determine if this is really possible. You'll have to figure out how to get the current form's data into the URL. You might be able to do this with:
Code:
<form action=&quot;...&quot; method=&quot;...&quot; onSubmit=&quot;replace(...)&quot;>
The other requirement is easier. Make the Back button that you placed in the form go directly to the home page with an onClick attribute:
Code:
<input type=&quot;button&quot; value=&quot;Go Back&quot; onClick=&quot;[URL unfurl="true"]http://home.domain.com&quot;>[/URL]
You might also want ot consider opening a new browser window that doesn't have the any of the browser's buttons and displaying the form in that window. This will leave the user with only your &quot;Back&quot; button available. If you do this, you will have to set the target of the back button to be the original window, and you will have to close the window that the form is displayed in.
 
isn't there a way to disable the browser's back button using javascript? or even to set the last page in the back history to something else?
 
Can't you prevent resubmits by simply putting a cookie or setting a session, client, or database variable that the current client is already logged in and shouldn't be allowed to resubmit? So even if they can go &quot;back&quot; with back button, they can't resubmit by clicking on submit button again.

Hope this helps.
 
try this:

<body onunload=&quot;location.replace()&quot;> or
<body onunload=&quot;location.replace(-1)&quot;>

by adding 1 or -1 you can manipulate what page will be erased in the browser's history... Sylvano
dsylvano@hotmail.com
 
In the template that processes the form, why not place a query before the INSERT code that checks the database for the information on the form, then if it exists, bypass the INSERT and display a message. Something like:

<cfif IsDefined(&quot;form.ID&quot;)>

<cfquery name=&quot;CheckTheID&quot; datasource=&quot;dsname&quot; type=&quot;ODBC&quot;>
SELECT ID FROM YourTable WHERE ID = '#Form.ID#'
</cfquery>

<cfif #CheckID.RecordCount# GT '0'>

<cfset Message = &quot;Hey, dimbulb, you can't do this twice.&quot;>

<cfelse>

<CFQUERY NAME=&quot;insert_stuff&quot; datasource=&quot;dsname&quot; type=&quot;ODBC&quot;>
INSERT SQL STUFF
</CFQUERY>

<cfset Message = &quot;Thanks, love. We'll be in touch.&quot;>

</cfif>

</cfif>

<cfoutput>
#Message#
</cfoutput>

NOTE: This assumes you are placing the unique ID in the form as a hidden field. I use CreateUUID() to set up the ID numbers in the form for just this purpose. Also, it allows you to preview data from the db right on the processing template.

Try it. You'll like it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top