Trouble with window.onBeforeUnload when compiled to Javascript

瀏覽次數:61 次
跳到第一則未讀訊息

Thomas Løcke

未讀,
2015年5月4日 上午8:19:442015/5/4
收件者: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

未讀,
2015年5月4日 上午9:52:032015/5/4
收件者:mi...@dartlang.org

Thomas Løcke

未讀,
2015年5月4日 上午11:12:582015/5/4
收件者:mi...@dartlang.org
Well yes, but isn't that then ultimately a dart2js problem, seeing as the code works perfect in Dartium?

Rasmus Eneman

未讀,
2015年5月4日 中午12:05:272015/5/4
收件者: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

未讀,
2015年5月4日 中午12:57:242015/5/4
收件者: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

未讀,
2015年5月5日 凌晨3:26:442015/5/5
收件者: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. 
回覆所有人
回覆作者
轉寄
0 則新訊息