Hello, I am working on a Training Management System. I want to notify my students before page reloading on exam. Like if a student wants to reload the page after starting an exam, he will get an alert(sweet alert I think). If a student wants to reload the page forcefully, the exam form will be submitted automatically. I succeed to prevent [ disable right button, keyboard reload ]. But I can't prevent page reloading by clicking browser reload button or url hit... So is there any way to show alert message and get confirmed before page reload using javascript or jquery or laravel or php? It would be a big help for me.
Sorry for my bad English. Thanks in advance.
@trin thanks for your reply trin. I tried beforemounte event. It shows an alert like confirm() but codes r execute before showing the alert in browser. like if I want to call an ajax request, the ajax request executes first and then the alert shows, it doesn't matter if I leave the page or stay in the page. Any suggestions? thanks
Just a side-note... javascript could be turned off in browser settings. You should make it so that the students won't be able to get into the exam without having javascript enabled.
@mainul islam You can’t override browser functionality such as the reload button. It belongs to the browser; not you.
As @trin mentions, add a listener on the beforeunload event to show an alert. This is how some websites display alerts if you say, partly complete a form but then try to navigate away (“You have unsaved changes. Are you sure you want to leave this page?”)
Ive done several exam type solutions and one that works well is to reload the page exactly as it was when they clicked reload. Using Livewire makes it easy to keep the server and client sessions in sync.