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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use Javascript to Clear previous two history entries

Status
Not open for further replies.

mhamilton3

Programmer
Oct 31, 2001
129
I know there are tons of entries using the keyword search that talk to this issue, but I have not found a solution that has worked for me. I have a perl program that saves some info, sends out emails, and then puts out a confirmation page. I need that confirmation page to not be able to go back. Every time it goes back it resends the email and resaves the info. Is there some way that I can say history.previous(1) = 'home.html' and history.previous(2).html - 'home.html'. I know that is not the way history.previous is used, but it should illustrate my needs. Thanks for any suggestions you might have.
 
You can't do that - it will break browser security.
Try some different methods - like not writing into brwoser history (in javascript you can use location.replace(url) or location.href=url ) or disabling back button.
 
have your confirmation page be two stages:

preconfirm.html:
Code:
<html>
<head>
<script language=&quot;javascript&quot;>
location.href=&quot;confirm.html&quot;;
</script>
</head>
</html>
confirm.html:
Your normal confirmation page. Have your Perl script send the user to preconfirm.html.

======================================

if (!succeed) try();
-jeff
 
I have read in numerous spots that you can not disable the back button (That would be the ultimate goal). I tried using location.replace(), but I must be doing something incorrectly because it jumps me to that page. I don't want to jump to a new page, I just want to set the history. And Jeff, thanks for the advice. My issue is the Perl program is a generic one that serves many many other pages. The page I need to update is a specific confirmation page. Is there a way to put at the top of a page

<script>
<!--
set the history to what I want
//-->
</script>

Bring up my confirmation page
 
mhamilton3,

let's see if i understand - your flow is:

entry page > perl script > confirmation page

...now when someone presses the back button on the confirmation page, you want to jump to the entry page?

======================================

if (!succeed) try();
-jeff
 
Bingo! One last bit. The confirmation page is a text file that is formatted as html. The perl program fills in variables in that text file and then renders it with print &quot;contents of text file&quot;. The confirmation file does not actually have it's own url. It is simply part of the call to the Perl program. So if you hit the back button it runs the entire Perl program again (leaving you back at the confirmation page) I would like it to go to the page prior to the call to the Perl script. Thanks
 
hmm...there's no way to trap the back button. the most you can do is present the user with a message before the page unloads using onbeforeunload, stating something like &quot;Pressing the Back button re-runs the program. Please click Cancel.&quot;
Code:
<body onbeforeunload=&quot;return 'Pressing the Back button re-runs the program.  Please click Cancel.';&quot;>
this message, however, will also show when the user tries to navigate OTHER than back too, unless you provide a mechanism for disabling the message when a valid link is clicked.

or, perhaps launch the results in a new window?
Code:
<form action=&quot;myPerlScript.pl&quot; method=&quot;post&quot; target=&quot;_blank&quot;>
======================================

if (!succeed) try();
-jeff
 
Thanks Jeff. I'm going the route of popping up a new window. It is just a little frustrating because I come from the application world where anything can be done if you do enough research. Limitations are not something I am used to...
 
yep - I agree because I've had some ideas shot down for these reasons - but these limitations do serve a purpose: for instance, what if we COULD disable all browser functions through script, then some pinhead's site redirects you to a less-than-clean site, full-screens your browser and essentially locks you out?

happy coding! ======================================

if (!succeed) try();
-jeff
 
As you already read in other posts, there seem to be no solution to your request using pure javascript due to different reasons.
Usually such things are made using cookies: when user submits a form the cookie is set (with some value like sent=&quot;1&quot;). When this page loads you have to run a script that reads the cookie: if it exists and the value=1 (i.e. the form was already sent) a page should redirect to the desired one, otherwise do nothing (i.e. allow to fill and submit a form).

Another scenario is to use server-side script that does almost the same thing, checking if the form was submit from current IP adderss.

good luck
 
Thanks for the info. The cookie idea is a great one, I did not think of that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top