我用React js.我需要检测page refresh
.当用户点击刷新图标或按F5时,我需要了解事件.
我使用javascript函数try 了stackoverflow post
我使用了javascript函数beforeunload
,但仍然不走运.
onUnload(event) {
alert('page Refreshed')
}
componentDidMount() {
window.addEventListener("beforeunload", this.onUnload)
}
componentWillUnmount() {
window.removeEventListener("beforeunload", this.onUnload)
}
这里有stackblitz的完整代码