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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Preventing user from leaving the page

    Hi,

    I have a requirement to display a message box and prevent user from leaving the page until he has saved fields on current page. Now the problem is that I am using a menu control (ComponentArt menu control). All is working fine for me unless the user drops down a menu (say File) and selects and submenu item (say open) and clicks upon it, the validation doesn't fire and the user gets able to leave to the clicked URL. Any ideas how can I accomplish this?

    Thanks & Regards,
    Omer Javed

  • #2
    New Coder
    Join Date
    Feb 2006
    Location
    Italy
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think you can try something like this:

    window.onunload=function(){
    if(fieldsNotSaved){
    return false;
    }
    }

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,625
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Once onunload is triggered your visitor has already left the page.

    Some browsers (but not all because it is non-standard) have an onbeforeunload event handler.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #4
    Senior Coder
    Join Date
    Feb 2006
    Location
    USA
    Posts
    1,013
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions
    Java != JavaScript && JScript != JavaScript
    Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.


  •  

    Posting Permissions

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