在Dart M8中卸载前提醒 [英] Alert before unload in Dart M8
问题描述
在dart里程碑8之前,不可能通过以下方法提醒用户离开页面:
As of dart milestone 8, it is not possible to alert the user before (s)he navigates away from the page by the following method:
window.onBeforeUnload.listen((BeforeUnloadEvent event) {
event.returnValue = 'Are you sure you want to leave?';
});
,因为Event.returnValue字段已删除。
如何使用新的API实现这个效果?
since the Event.returnValue field has been removed. How do you accomplish this effect with the new API?
这是如何使用jQuery:
This is how it's done with jQuery:
$(window).on('beforeunload', function(){
return 'Are you sure you want to leave?';
});
推荐答案
新的Blink版本 - Blink最终本地添加了BeforeUnloadEvent。在此之前,我们必须伪造它。
It looks like the API got dropped when we integrated a new Blink version- Blink finally added the BeforeUnloadEvent natively. Prior to that we had to fake it.
查看错误 https://code.google.com/p/dart/issues/detail?id=14641
解决方法:像以前一样使用它。传入的事件是BeforeUnloadEvent的子类,并且仍然具有returnValue。
Workaround: use it just as before. The event being passed in is a subclass of BeforeUnloadEvent and still has returnValue.
这篇关于在Dart M8中卸载前提醒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!