1

I am developing one stepwise form application where I am displaying some information on Modal popup. I am able to display the required information. If I refresh the page when the Modal is open the current Modal will close. Is there any way to stop closing the Modal on page refresh?

Shrinika
  • 11
  • 1
  • 4
  • I don't think you could do that. The best you could do is shoot an alert to the users that they will be destroying the content. This link could help - https://stackoverflow.com/a/7080331/7643022 – Sagar Sep 18 '17 at 09:37

1 Answers1

0

You can not prevent user clicking the refresh button. Instead you can keep the state of the form in the local storage and in the page load event check if the user was in the middle of the form process.

If so, just show the modal again. There's no any other way.

//This is an example. This should be added when the user seen the dialog.
//This is just a Bootstrap example. Just to demonstrate the logic.
$("#modal-dialog").on("shown.bs.modal", function(){
  localStorage.setItem("IS_SET", true);
});

$("#modal-dialog").on("hidden.bs.modal", function(){
  localStorage.setItem("IS_SET", false);
});

$(document).ready(function(){
  if(localStorage.getItem("IS_SET") && localStorage.getItem("IS_SET") === true){
     //Which means the user was in the form process.
     //And show the modal again on page refresh.
     $("#modal-dialog").modal("show");
  }
});

If you don't like the localstorage method, you can set a URL param which can be seen publicly in the URL.

Thusitha
  • 3,393
  • 3
  • 21
  • 33