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

Client side JS code re-executes upon "BACK" button 1

Status
Not open for further replies.

masif2000

Programmer
Jul 21, 2005
9
0
0
US
I have a HTML form on my ASP page. It submits to the same page (itself). On the submit, it makes a database call (based on the user input) and stores an output varaible (coming back from that call) into a session variable.

On the client-side of it, I have some javescript code based on that session variable. Now everything works fine upto this point. But when the user moves from that page and then hits the BACK button, the javascript code executes again that has already executed before.

I have tried everything to prevent it from happening. I have tried to reset the session variable but hitting the back button takes the user back to the previous state of the page when the session variable was not "reset." What am I doing wrong? I must be missing something very very basic.
 
I had a situation where the data on the form was sensitive and could not remain after submission so after processing the data to submit I did a clear on the form. Then if the page is reloaded the data is already wiped out.

Or as soon as the page loads you can do a clear to make certain all values are emptied before any other functions can execute.


Paranoid? ME?? WHO WANTS TO KNOW????
 
niteowl,

In the same situation, I usually put

history.forward();

...at the top of my page's script. When the user arrives there "legitimately," there is nowhere forward to go. If the user arrives there via the Back button, the page goes forward before the rest of the javascript is executed.

I don't know if this is what masif needs, but your post reminded me of this.

masif, are you trying to prevent use of the Back button?

--Dave
 
Ooh. Thanks and Cheers to you too! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top