gpt4 book ai didi

javascript - 有没有办法在 HTML5 通知消失时执行操作?

转载 作者:行者123 更新时间:2023-12-03 02:51:08 27 4
gpt4 key购买 nike

根据 MDN,Notification API 的 onclose 事件已过时:

The following event handlers are still supported as listed in the browser compatibility section below, but are no longer listed in the current spec. It is safe therefore to assume they are obsolete and may stop working in future browser versions.

我有一个脚本,在某些情况下会生成以下通知:

X has happened. Click here to deal with it, ignore or close this notification to continue running.

如果用户单击通知,脚本将停止,用户可以处理这种情况。如果未单击通知,则脚本将在通知关闭/消失后继续工作。

现在 onclose 事件已被弃用,如何执行此操作?

最佳答案

同时根据MDN ,您应该发送自己的 close 命令,因为 Chrome 不会自行执行此操作。拉拢它来处理该事件是微不足道的。

类似这样的事情:

let notification = new Notification('Test Notification');

setTimeout(close(notification), 5000);

function close(n) {
n.close.bind(n);
// your other code...
}

关于javascript - 有没有办法在 HTML5 通知消失时执行操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47856622/

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