Trouble with window.onBeforeUnload when compiled to Javascript

61 views
Skip to first unread message

Thomas Løcke

unread,
May 4, 2015, 8:19:44 AM5/4/15
to mi...@dartlang.org
Hi all,

I'm having some problems getting window.onBeforeUnload to work when compiled to JS.

It works just fine in Dartium, but neither Chrome nor Firefox seems to care.

The code is dead simple:

void main() {
  window.onBeforeUnload.listen((_) {
    return 'foo';
  }); 
}

In Dartium that pops a neat little box when trying to either refresh the page or close the page.

Compiled to JS I get nothing: The page just refresh or close without warning.

Have I stumbled on a dart2js bug, or am I missing something?

:o)
Thomas

Günter Zöchbauer

unread,
May 4, 2015, 9:52:03 AM5/4/15
to mi...@dartlang.org

Thomas Løcke

unread,
May 4, 2015, 11:12:58 AM5/4/15
to mi...@dartlang.org
Well yes, but isn't that then ultimately a dart2js problem, seeing as the code works perfect in Dartium?

Rasmus Eneman

unread,
May 4, 2015, 12:05:27 PM5/4/15
to mi...@dartlang.org
The thing is, streams doesn't know about the listeners return value.
According to very old code (nearly a year) there is a returnValue setter on the passed event object which the message should be set to.
Kind of strange it works in Dartium though :/

Alan Knight

unread,
May 4, 2015, 12:57:24 PM5/4/15
to mi...@dartlang.org
Yes, I think you set should set the returnValue on the event to have that used. I don't know why it would work in Dartium, there isn't anything obvious in the code, but I suspect we'll fix that glitch :-)


--
For other discussions, see https://groups.google.com/a/dartlang.org/
 
For HOWTO questions, visit http://stackoverflow.com/tags/dart
 
To file a bug report or feature request, go to http://www.dartbug.com/new

To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.

Thomas Løcke

unread,
May 5, 2015, 3:26:44 AM5/5/15
to mi...@dartlang.org
Hi Rasmus,


Den mandag den 4. maj 2015 kl. 18.05.27 UTC+2 skrev Rasmus Eneman:
The thing is, streams doesn't know about the listeners return value.
According to very old code (nearly a year) there is a returnValue setter on the passed event object which the message should be set to.
Kind of strange it works in Dartium though :/


You are the man Rasmus! Thanks a bunch. I changed the type from plain Event to BeforeUnloadEvent and BAM! then I had event.returnValue available. Setting that fixed it. It now works both in Dartium and when compiled to JS.

Why it worked before in Dartium: I have no idea. 
Reply all
Reply to author
Forward
0 new messages