How to use dhtmlx.confirm to allow/prevent closing a window

For a particular window(id) I have an ‘onClose’ function with the following code:

        dhtmlx.confirm({
            text: 'You have Pending transactions<br/>Press YES to exit or NO to stay',
            cancel: 'NO',
            ok: 'YES',
            callback: function(btn){if(btn == true)
            {

                return = true;
            }
            else
            {
                return = false;
            }
        }});

However since dhtmlx.confirm is non-blocking it reaches the end of the function and by default it returns false. So I can’t close the window at all.

Please can you tell me what is the correct way of using dhtmlx.confirm to achieve this.

Thanks

I finally solved this by changing the '‘onClose’ function as follows:

    function doUnLoad()
    {
        if(CloseWindow == true)
        {
            return true;
        }
        dhtmlx.confirm({
            text: 'You have Pending transactions<br/>Press YES to exit or NO to stay',
            cancel: 'NO',
            ok: 'YES',
            callback: function(btn){if(btn == true)
            {
                CloseWindow = true;
                parent.winMenuOpts.window('winAddEditCshTrn').close();

            }
        }});
    }

The CloseWindow variable is a Global variable which I set to ‘false’ in the onLoad function. Haviing a Global variable is the only thing that I’m not too keen on.

I’m still hoping that the DHTMLX team can suggest a better option.

1 Like