首页 > 解决方案 > 页面刷新后保持模态

问题描述

我正在一个项目中工作,我在某些条件下显示一些模态,经过一些工作后,我意识到如果我在显示模态时尝试刷新页面,模态就会消失。

我想知道是否有一种方法可以让我在刷新页面时呈现模式。

我试过这个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 的情况下,我可以看到模态,但是当我刷新它时它消失了。

如果我刷新页面,我可以在短时间内看到模态框,但它不会自己保持。

有没有办法让我保持模式,如果它被显示,刷新后包含?

路易斯

标签: javascriptdjangomodal-dialog

解决方案


推荐阅读