Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Unload event
Fri, Aug 14 2015 6:39 AMPermanent Link

squiffy

Telemix Ltd.

Avatar

Is it possible to fire an event before a closed browser tab removes the application? I appreciate it might be unreliable and it's not critical, just desirable if possible.
Fri, Aug 14 2015 10:52 AMPermanent Link

Rick

squiffy wrote:

>>Is it possible to fire an event before a closed browser tab removes the application? I appreciate it might be unreliable and it's not critical, just desirable if possible.<<

You could try the following ...

unit Unit1;

interface

uses WebCore, WebUI, WebForms, WebCtrls, WebDOM;

type

  TForm1 = class(TDialog)
     procedure Form1Create(Sender: TObject);
  private
     { Private declarations }
  public
     { Public declarations }
     function unload(event: TEvent): string;
  end;

var
  Form1: TForm1;

implementation

procedure TForm1.Form1Create(Sender: TObject);
begin
setwindoweventhandler(window,'beforeunload',unload);
end;                                                

function TForm1.unload(event: TEvent): string;
begin
window.alert('here');
Result:='some text';
end;

end.

Best to use the onbeforeunload event rather than onunload because more of the EWB environment is probably available.

When running from the IDE the alert and the leaving page prompt work correctly. When running from a browser (Firefox, IE) window.alert gives an exception (viewable via developer tools) and the result text which should force the prompt is ignored. Don't know why. Maybe the EWB environment is already unstable at this point so don't know how much you will be able to do within the event.

--  
Rick
Sat, Aug 15 2015 12:23 PMPermanent Link

squiffy

Telemix Ltd.

Avatar

Thanks, I'll give it a go.
Image