gpt4 book ai didi

javascript - Enyo onbeforeunload 事件

转载 作者:行者123 更新时间:2023-11-30 12:58:20 26 4
gpt4 key购买 nike

我正在尝试在我的应用程序中为 onbeforeunload 附加一个监听器,但它似乎没有被 enyo.Signals 捕获。

根据Documentation :

Within the Enyo framework itself, DOM events that have no node targets are broadcast as signals. These events include window events, like onload and onbeforeunload, and events that occur directly on document, like onkeypress if document has the focus. Signals are also useful for hooking up non-Enyo events (e.g., PhoneGap events) to be handled by Enyo kinds in application code.

我写了下面的测试用例:

 enyo.kind({
name: "App",
kind: "enyo.Control",
fit: true,
content: "Hello World",

components:[
{kind: "enyo.Signals", onbeforeunload: "test"}
],

test: function(inSender, inEvent) {
return 'You have unsaved changes!';
}
});

当我关闭选项卡或离开页面时,这似乎没有任何效果。我错过了什么?这是 JSFiddle

最佳答案

看起来我们没有默认处理beforeunload:

https://github.com/enyojs/enyo/blob/master/source/dom/dispatcher.js

但是,你可以让它与类似的东西一起工作

enyo.dispatcher.listen(window, "beforeunload");

关于javascript - Enyo onbeforeunload 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18271554/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com