Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 12 total
Thread Leaving Page Warning
Sat, Jan 2 2016 12:47 PMPermanent Link

squiffy

Telemix Ltd.

Avatar

Is there a way to trap the back button to show a "You are leaving the page - are you sure?" style warning?
Sat, Jan 2 2016 4:44 PMPermanent Link

squiffy

Telemix Ltd.

Avatar

(or just detect you're leaving the app in general, back button or otherwise).
Sat, Jan 2 2016 5:08 PMPermanent Link

Rick

> squiffy wrote:
>
> Is there a way to trap the back button to show a "You are leaving the page - are you sure?" style warning?

You could try this:

http://www.elevatesoft.com/forums?action=view&category=ewb&id=ewb_general&msg=6644

I don't know whether or nor official support has been added in the meant time.

--  
Rick
Sun, Jan 3 2016 6:26 AMPermanent Link

squiffy

Telemix Ltd.

Avatar

Hi,
even though I had forgotten about that question entirely (I'm getting old) and it didn't come up in my searching (I'm rubbish as searching), it's not really usable as it doesn't reliably (in my testing at least) show a dialogue box and give the user the choice of cancelling the move away.

There's lots of examples on SO for using raw JS to do this, but I'm never sure how well anything external is playing with EWB which is why I'd love to know how people here are doing it, if at all.

Thanks,
Sun, Jan 3 2016 9:34 AMPermanent Link

Raul

Team Elevate Team Elevate

On 1/3/2016 6:26 AM, squiffy wrote:
> it's not really usable as it doesn't reliably (in my testing at least) show a dialogue box and give the user the choice of cancelling the move away.

In which way ? Mobile browsers generally do not support unload event at
all (even if done direct in JS) but it should be reliable on desktop.

> There's lots of examples on SO for using raw JS to do this, but I'm never sure how well anything external is playing with EWB which is why I'd love to know how people here are doing it, if at all.

Can you link some of those examples ?

AFAIK the way to accomplish what you're asking for is to use
onbeforeunload JS event - and to do that you need to add "beforeunload"
event handler using addeventlistener which is what the linked sample i
believe does.

Raul
Sun, Jan 3 2016 10:12 AMPermanent Link

squiffy

Telemix Ltd.

Avatar

Here's one such example : http://stackoverflow.com/questions/7317273/warn-user-before-leaving-web-page-with-unsaved-changes

I know it also deals with unsaved changes, but the principle is the same, I just wouldn't have any of the extra checks for dirty data in as just leaving the app is enough to warrant the challenge.

That example code just doesn't do anything for me at all. No obvious acknowledgement that the event even fired. I'll play around more tomorrow and see if I can get something working. I suppose I was just hoping that someone had a working example specific to EWB. Doesn't matter, I'll get there.
--
I really, really hate web programming.
Sun, Jan 3 2016 10:31 AMPermanent Link

squiffy

Telemix Ltd.

Avatar

(by example code I mean the link to the EWB code above, not the SO code).
--
I really, really hate web programming.
Sun, Jan 3 2016 11:34 AMPermanent Link

Raul

Team Elevate Team Elevate

<< squiffy wrote:
(by example code I mean the link to the EWB code above, not the SO code).
>>

I just tried and it works fine here (Chrome  and IE). Event fires on all common exit scenarios : back button, closing tab or entering new URL.




here's my entire sample project code:

unit main;

interface

uses  WebDOM, WebCore, WebUI, WebForms, WebCtrls, WebLabels;

type

  TForm1 = class(TForm)
     Label1: TLabel;
     procedure Form1Create(Sender: TObject);
  private
     { Private declarations }
     function unload(event: TEvent): string;
  public
     { Public declarations }
  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('unload has been called');
  Result:='dont go';
end;


end.
Mon, Jan 4 2016 3:39 AMPermanent Link

Matthew Jones

Raul wrote:

> I just tried and it works fine here (Chrome  and IE). Event fires on
> all common exit scenarios : back button, closing tab or entering new
> URL.

Does this have the ability to stop the tab closing? I presume it is
possible to do as my son got stuck in a spammer trap the other day. The
dialog was full of a really long message that took the buttons off the
bottom of the screen so his only option was to click the close button
which cancels the tab close.

--

Matthew Jones
Mon, Jan 4 2016 8:16 AMPermanent Link

Raul

Team Elevate Team Elevate

On 1/4/2016 3:39 AM, Matthew Jones wrote:
> Does this have the ability to stop the tab closing?

Not by itself - most browsers just put up a confirmation prompt on
whether you want to leave the page.

> possible to do as my son got stuck in a spammer trap the other day. The
> dialog was full of a really long message that took the buttons off the
> bottom of the screen so his only option was to click the close button
> which cancels the tab close.

Haven't seen this myself but looks like a browser bug.

Raul
Page 1 of 2Next Page »
Jump to Page:  1 2
Image