Uncaught ReferenceError: Notification is not defined

Uncaught ReferenceError: Notification is not defined

我认为我的对象检测会起作用:

if (Notification!=undefined) {}

但是我的 JavaScript 日志仍然显示以下错误:

Uncaught ReferenceError: Notification is not defined

如何正确地对 Notification 对象进行对象检测?

没有框架。

您可以像这样使用 typeof

if (typeof Notification !== 'undefined') {

}

如果您使用 typeof,它不会尝试实际 使用 变量(中断并引发错误)