Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder feras_wilson's Avatar
    Join Date
    Jul 2005
    Location
    Sweden
    Posts
    129
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question How to get Confirm before leaving in HTA

    Hi all!
    I have readed about it's possible to get a confirm before leaving and i have done it:
    Code:
    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!
    Exp:
    PHP
    .NET

  • #2
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by feras_wilson View Post
    Hi all!
    I have readed about it's possible to get a confirm before leaving and i have done it:
    Code:
    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!
    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.

    Code:
    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; 
     } 
    }

  • #3
    Regular Coder feras_wilson's Avatar
    Join Date
    Jul 2005
    Location
    Sweden
    Posts
    129
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Arty Effem View Post
    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.

    Code:
    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!!
    Exp:
    PHP
    .NET


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •