Skip navigation
Currently Being Moderated

Confirmation upon browser window close event

Jan 25, 2010 11:53 AM

Our web application open a popup browser window contains a cutomized LiveCycle workspace from where the user submit a data form. I want to implement a feature that when the user close the browser window, a message box will pop up for user's confirmaiton (OK to close the window, Cancel to remain in the workspace window). Here is my code:


In javascript:


    <script LANGUAGE="JavaScript">


        window.onbeforeunload = confirmExit;
        var needToConfirm = true;
        var confirmMsg = "Are you sure you want to exit this page?"
        function confirmExit() {
            if (needToConfirm) {
                alert("Event triggered!");
                event.returnValue = confirmMsg;
                //return confirmMsg;


        function setNeedConfirm() {
            needToConfirm = true;
        function releaseNeedConfirm() {
            needToConfirm = false;




In *.mxml:"releaseNeedConfirm"); or"setNeedConfirm");



This approach works perfectly with IE, but for some reason it does not work with FireFox. I confirmed that the line alert("Event triggered!") is reached in FF, but no confirmation box is popped up.


Anyone can help me here?





  • Currently Being Moderated
    Jan 25, 2010 9:17 PM   in reply to johnzli

    Just change the line of code:


    event.returnValue = confirmMsg;  


    as the following;


    event.preventDefault = confirmMsg;



    Hope this will work!



    Mark as:
  • Currently Being Moderated
    Jan 26, 2010 6:27 AM   in reply to johnzli

    The code I mentioned is applicable only to FireFox.


    To make your logic work on both browsers, you need to find out the browser type and should handle the event accordingly.



    Mark as:
  • Currently Being Moderated
    Jan 26, 2010 6:30 AM   in reply to johnzli

    You can detect the browser type by:


    var browser=navigator.appName;

    var b_version=navigator.appVersion;

    var version=parseFloat(b_version);

    alert("Browser name: "+ browser);

    alert("Version: "+ version);





    Mark as:
  • Currently Being Moderated
    Jan 26, 2010 6:37 AM   in reply to johnzli

    I will try to make an example and then let you know.



    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points