我想提醒人们在离开页面之前确认一下。我在componentDidMount中添加了事件侦听器: window.addEventListener('beforeunload', this.onUnload)然后我写下了我想要发生的事件: var message = "Random message to trigger the browser
作为MVC web应用程序的一部分,我需要在关闭浏览器或浏览器选项卡时调用控制器方法。我使用Javascript onbeforeunload事件来调用该方法。} function preventNavigation(message) {
varAny changes will be lost if you leave this page."
那时一切都很好,直到我看到它今天在Google Chrome version 51.0.2704.103m上不起作用为止。;它没有显示我的自定义消息,而是显示:我们的浏览器是否仍然支持在卸载之前重写our消息?因为这个问题在Mozilla Firefox version 47.0.1中是一样的。
还是我做错了?