在Dart M8中卸载前发出警报

从飞镖里程碑8开始,在通过以下方法导航离开页面之前无法提醒用户:

window.onBeforeUnload.listen((BeforeUnloadEvent event) { event.returnValue = 'Are you sure you want to leave?'; }); 

因为Event.returnValue字段已被删除。 如何使用新API实现此效果?

这是用jQuery完成的:

 $(window).on('beforeunload', function(){ return 'Are you sure you want to leave?'; }); 

当我们集成一个新的Blink版本时,看起来API被删除了 – Blink最终在本地添加了BeforeUnloadEvent。 在此之前我们不得不假装它。

请参阅错误https://code.google.com/p/dart/issues/detail?id=14641

解决方法 :像以前一样使用它。 传入的事件是BeforeUnloadEvent的子类,仍然具有returnValue。