Detecting the exit button click in a browser dialog's JavaScript

Neither of those are firing for me in SU2016 web dialog w/ document mode set to IE11 (or IE9.)

I gave up on the JavaScript close / beforeunload / unload event trapping.

WebDialogs: The Lost Manual > JavaScript events and functions > window.close says:

This works in Safari, but not in Internet Explorer.

So, I suppose if the method does not work, we cannot expect the event of the same name to either.
(Note this manual refers to dialogs in browser frames embedded in a SketchUp process, not to a standalone browser instance.)


This is the Ruby-side solution I am using …

I have a result variable (@result) that is set to 0 initially before the dialog is created.

If the user acts normally, and either uses the ESC or ENTER keys, or clicks on of the dialog’s buttons, the "clicked" dialog’s callback fires setting the @result variable to a button integer code (can be -1 or > 1.)

The "clicked" callback will close the dialog after setting @closed_by_callback to true and @result to the button code, … then do cleanup work.

If the dialog window is closed by the X button, then @closed_by_callback will still be false and @result will still be 0, so I’ll use a Ruby-side closure handler block …

@window.set_on_close {
  if !@closed_by_callback && @result == 0
    # User must have clicked the X button, therefore ...
    @result = IDCANCEL # which is 2
    # This block gets called TWICE by SketchUp because of a bug,
    #   so prevent tasks from executing more than once ...
    @closed_by_callback = true
    # Do other cleanup tasks that the normal callbacks do
    #   when the user clicks a button or presses ESC key.
  end
}

This will allow my code to proceed as if the Cancel button was clicked, or the ESC key was pressed. This is important as the code calling the dialog creation method needs to react to the result.


The following was disproved by Steve and Gordon (below) …

IF … it turns out that the UI::WebDialog # set_on_close() block is not being called on the Mac for SketchUp 2016 specifically, then I just will not support Mac for v 16. (Simple as this.)

@slbaumgartner Do you know (or remember) if SU2016 on Mac will call the set_on_close block when the dialog window is closing ?