javascript - 页面刷新后保持模态
问题描述
我正在一个项目中工作,我在某些条件下显示一些模态,经过一些工作后,我意识到如果我在显示模态时尝试刷新页面,模态就会消失。
我想知道是否有一种方法可以让我在刷新页面时呈现模式。
我试过这个java脚本代码:
// Get the modal
var modalBtn = document.getElementById("modalBtn");
// // Get the button that opens the modal
// var buttonModal = document.getElementById("buttonModal");
window.onbeforeunload = function (evt) {
buttonModal.click();
console.log("refresh")
}
// //hold modal
buttonModal.addEventListener('click', () => {
// //show error modal
$("#modal_error").modal()
})
在我单击 buttonModal 的情况下,我可以看到模态,但是当我刷新它时它消失了。
如果我刷新页面,我可以在短时间内看到模态框,但它不会自己保持。
有没有办法让我保持模式,如果它被显示,刷新后包含?
路易斯
解决方案
推荐阅读
- css - Flexbox:等高行?
- qt - 如何使用来自外部 QML 文件的内部 QML 类型?
- python - 需要从宽转换为长
- go - 在 Golang 中使用反射覆盖结构值
- bash - Bash 脚本从存储在变量中的列表创建新文件夹
- android - 使用 Material Design 主题时如何自定义 TextInputLayout?
- google-bigquery - 如何在 BigQuery 标准 SQL 中获取数组的切片?
- mysql - 我无法更新我的实体表(Spring Boot 2 hibernate 5)
- firebase - 通过电子邮件从 Firebase 发送调查链接
- r - 线性回归:行(作为观察)与变量