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!

page exit confirmation

Status
Not open for further replies.

mgriffith

MIS
Jul 3, 2001
177
0
0
US
i know that i can run a script in <body onunload=&quot;funtion();&quot;>

what i want to know is, can i stop the user from leaving if they accidentally clicked exit. the reason is that i'm making a data entry page, and if they leave the page, their session state is ruined.

i know that you can do a <form onsubmit=&quot;return confirm();&quot;> and if confirm() is false then it won't submit, but this doesn't work for leaving a page.

i realize that this probably wasn't intentionally built right into iexplore because it'd be pretty crappy to get a malicious programming that wouldn't let you leave his site, but does anyone know any workarounds?

the only thing i can think of is
<body onunload=&quot;if (!confirm('are you sure you want to leave')) { window.location.href=unescape(window.location.href); }&quot;>
but then i lose the form elements that had been submitted to the page....unless maybe i used get instead of post...i'll try that.

thanks. mike griffith
----------------------------
mgriffith@lauren.com
mdg12@po.cwru.edu
 
... or you could store the form information in a temporary cookie and refresh the form elements in the event of a DOH! Paul Ellis
[hammer] I've been programming since you had to punch holes in cards to code. (Always remember, number your cards!)
 
yes, and it's simple:

<body onbeforeunload=&quot;return 'Click OK to close.';&quot;>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top