what I am attempting to do is take a web form and attach a
confirm to leave page. I can get the event to fire (though
it doestn actually prevent navigating away from the site)
My problem is that every time I initiate a postback, the
event is also fired. I dont want people to see "Are you
sure you wish to discard any changes?" if they hit refresh
or postback etc.
ANyway I can get around this?"Weston Weems" <anonymous@.discussions.microsoft.com> wrote in message
news:621201c4cc2e$7a655640$a401280a@.phx.gbl...
> Ok,
> what I am attempting to do is take a web form and attach a
> confirm to leave page. I can get the event to fire (though
> it doestn actually prevent navigating away from the site)
> My problem is that every time I initiate a postback, the
> event is also fired. I dont want people to see "Are you
> sure you wish to discard any changes?" if they hit refresh
> or postback etc.
> ANyway I can get around this?
You can't really do this. Remember that by the time the client sees the web
page, the code has finished on the server. Once the page has been sent to
the client, the server has no further connection to the client, and cannot
know when the client closes his browser.
All of this sort of thing has to be done on the client, in script.
John Saunders
Thats what I am doing...
<body onUnLoad="confirm_method();"> etc...
I dont mind using clientscript... my problem is that
postbacks cause the onUnLoad to fire off.
Maybe in onunload, I'll check querystring and if its not
my site, confirm leave.
>--Original Message--
>"Weston Weems" <anonymous@.discussions.microsoft.com>
wrote in message
>news:621201c4cc2e$7a655640$a401280a@.phx.gbl...
>> Ok,
>>
>> what I am attempting to do is take a web form and
attach a
>> confirm to leave page. I can get the event to fire
(though
>> it doestn actually prevent navigating away from the
site)
>>
>> My problem is that every time I initiate a postback, the
>> event is also fired. I dont want people to see "Are you
>> sure you wish to discard any changes?" if they hit
refresh
>> or postback etc.
>>
>> ANyway I can get around this?
>You can't really do this. Remember that by the time the
client sees the web
>page, the code has finished on the server. Once the page
has been sent to
>the client, the server has no further connection to the
client, and cannot
>know when the client closes his browser.
>All of this sort of thing has to be done on the client,
in script.
>John Saunders
>
>.
you want unbeforeunload(). you will have to put in code that checks that a
submit was done.
<body onbeforeunload="return doUnload()"
<form ...
...
</form>
<script>
var unloadOk = false;
function doUnload() {
if (!unload) return "Lose data changes?";
return;
}
window.__doPostBack = function (eventTarget, eventArgument) {
var theform = document.forms[0];
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
unloadOk = true;
theform.submit();
}
var oldOnSubmit = document.forms[0].onsubmit;
window.onsubmit = function()
{
unloadOk = true;
if (oldOnSubmit) oldOnSubmit();
}
</script
"Weston Weems" <anonymous@.discussions.microsoft.com> wrote in message
news:621201c4cc2e$7a655640$a401280a@.phx.gbl...
| Ok,
|
| what I am attempting to do is take a web form and attach a
| confirm to leave page. I can get the event to fire (though
| it doestn actually prevent navigating away from the site)
|
| My problem is that every time I initiate a postback, the
| event is also fired. I dont want people to see "Are you
| sure you wish to discard any changes?" if they hit refresh
| or postback etc.
|
| ANyway I can get around this?
0 comments:
Post a Comment