You are here: irt.org | FAQ | JavaScript | Form | 11 | Q685 [ previous next ]
You'll not be able to stop someone from leaving the page in all cases. You can trap people selecting links on your page and then cancel them selectively, but not if the user uses the back of forward button, or selects an item from the history, or types in a url.
For links try:
<SCRIPT LANGUAGE="JavaScript"><!-- var changed = false; function gothere(href) { if (changed) { if (confirm("Are you sure?")) window.location.href = href; } else window.location.href = href; } //--></SCRIPT> <FORM onSubmit="changed=false"> <TEXTAREA onChange="changed=true;alert('changed');"></TEXTAREA> <INPUT TYPE="SUBMIT" </FORM> <A HREF="javascript:gothere('http://www.irt.org')">http://www.irt.org</A>