javascript - 如何在 Angular 6+ 中检测浏览器关闭事件或标签关闭事件?
问题描述
我已经@HostListener
在我的 AppComponent 类中编写来检测浏览器关闭或标签关闭。
我已经编写了这段代码,但它不起作用。请帮助我理解为什么我的代码不起作用
下面是我的代码。
export class AppComponent {
@HostListener('window:unload', [ '$event' ])
unloadHandler(event) {
alert('call unload');
}
@HostListener('window:beforeunload', [ '$event' ])
beforeUnloadHander(event) {
alert('call beforeunload');
}
}
解决方案
推荐阅读
- javascript - 用 JS 实现 CRC8 校验和
- spring - 无法从 LocalContainerEntityManagerFactoryBean(休眠 OGM 提供程序)检索 EntityManager
- reactjs - 如何编写测试用例以使用 mocha nyc 为 API 传递代码覆盖率?
- scala - 如何解决依赖项 com.typesafe.play#play-json;2.4.0
- django - FOREIGN KEY 约束在信号中失败
- r - 在堆叠的 geom_col 图的最大值处添加 geom_point - 由变量结果着色
- docker - Docker-compose:Docker 容器无法使用服务名称进行连接
- python-3.x - 用于 model.trainable_variables 的 tape.gradient 返回 None 值
- javascript -
如果 searchTerm 以编程方式提供,则在更改 formGroup 控件值后仍为空 - php - 如何访问数组内部的数组