reactjs - 当用户在 React 中按下浏览器后退或下一步按钮时,有什么方法可以提示 MessageBox
问题描述
我写了这样的东西,但我确信它是不正确的。
window.onpopstate = (e) => {
MessageBox.showConfirmMessage('You clicked back or foward button. Go and lose changes?').then(result => {
if (!result.confirm) {
window.history.pushState(null, null, window.location.pathname);
}
});
}
解决方案
你试过这个(两者)?
window.onbeforeunload = function () {
return 'Are you sure you want to go leave page?';
};
推荐阅读
- javascript - 使用 javascript (Bookly WP 插件) 选择一个下拉值
- c# - C#应用程序从php接收数据
- android - 如何在 Android Studio 中选择其他 api 级别?
- c++ - 如何获取所有 wxListbook 项目?
- sql - SQL Server:对今年和去年的特定列求和
- python - 错误“pip install boto3”
- python - 预期 2D 数组,在尝试反转缩放数据时得到 1D 数组
- python - 如何按“国际象棋顺序”对数组或查询集进行排序?
- matlab - 如何在 Matlab 中加载多个音频文件?
- javascript - 如何修复javascript实时语法突出显示中的反向文本?