How do you determine the reason for an UNLOAD

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When a client requests to leave a Web Page, I want the web page to check for a certain condition. If that condition is met, I want to prompt the user to make sure they want to leave

The method I am currently using is
<HTML><HEAD
..
<script><!-
function PageBeforeUnloadCheck(

..
if (...)AdministratorStatusReportSummaryForm.TheReportTypes.value ==
event.returnValue = "The Summary has not been saved!"


--></script></HEAD><body onbeforeunload="PageBeforeUnloadCheck()"
..
</body></HTML

My problem is that the java function PageBeforeUnloadCheck is executed for every PostBack, not just when the page is going to change or the browser closed. After some thought, this makes sense because the client site does not know what the response will be, it might be a new page address. My problem is that I cannot figure out how the java script can know what action the client took. Was it a button press, the change in selection of a dropdownlist, or ...

What variable/parameter/attribute can the script use to determine the user action?
 
I think I have figured it out. I found "document.activeElement.id". This seems to give the id of the last button clicked. What I can do is check it. Since closing the window does not update this property, I find I can set it to "" after my check and then when the window is closed the value is "" not the last button's id.
 
Wrong group.

Try the .aspnet group

Shane

Michael SL said:
When a client requests to leave a Web Page, I want the web page to check
for a certain condition. If that condition is met, I want to prompt the
user to make sure they want to leave.
The method I am currently using is:
<HTML><HEAD>
...
<script><!--
function PageBeforeUnloadCheck()
{
...
if (...)AdministratorStatusReportSummaryForm.TheReportTypes.value == {
event.returnValue = "The Summary has not been saved!";
}
}
--></script></HEAD><body onbeforeunload="PageBeforeUnloadCheck()">
...
</body></HTML>

My problem is that the java function PageBeforeUnloadCheck is executed for
every PostBack, not just when the page is going to change or the browser
closed. After some thought, this makes sense because the client site does
not know what the response will be, it might be a new page address. My
problem is that I cannot figure out how the java script can know what action
the client took. Was it a button press, the change in selection of a
dropdownlist, or ....
What variable/parameter/attribute can the script use to determine the user
action?
 
Back
Top