...

View Full Version : How to get Confirm before leaving in HTA



feras_wilson
12-11-2006, 09:34 PM
Hi all!
I have readed about it's possible to get a confirm before leaving and i have done it:


window.onbeforeunload = askConfirm;
function askConfirm(){
return "You have unsaved changes.";
}

The problem is when i use the function in HTML Application (HTA). I get a confirm message, but even if i click on "OK" or on "Cancel" the window close.
I need help, please!:confused: :confused:

Arty Effem
12-11-2006, 09:49 PM
Hi all!
I have readed about it's possible to get a confirm before leaving and i have done it:


window.onbeforeunload = askConfirm;
function askConfirm(){
return "You have unsaved changes.";
}

The problem is when i use the function in HTML Application (HTA). I get a confirm message, but even if i click on "OK" or on "Cancel" the window close.
I need help, please!:confused: :confused:This is the way I do it, derived from code on the Microsoft site. formStarted and formSent are variables that I set whenever a form element is focused or the form is submitted respectively. You don't need such a test, it's just an enhancement that I added to prevent false triggering.


window.onbeforeunload = function (evt)
{
var message = '!! Leaving this page may delete your entries !!\n';

if(formStarted && !formSent)
{
if (typeof evt == 'undefined')
evt = window.event;

if (evt)
evt.returnValue = message;

return message;
}
}

feras_wilson
12-11-2006, 09:53 PM
This is the way I do it, derived from code on the Microsoft site. formStarted and formSent are variables that I set whenever a form element is focused or the form is submitted respectively. You don't need such a test, it's just an enhancement that I added to prevent false triggering.


window.onbeforeunload = function (evt)
{
var message = '!! Leaving this page may delete your entries !!\n';

if(formStarted && !formSent)
{
if (typeof evt == 'undefined')
evt = window.event;

if (evt)
evt.returnValue = message;

return message;
}
}

I get the same problem!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum